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 "pyistream.h"
20 #include <wx/resource.h>
21 #include <wx/tooltip.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 // Put some wx default wxChar* values into wxStrings.
56 DECLARE_DEF_STRING(FileSelectorPromptStr);
57 DECLARE_DEF_STRING(FileSelectorDefaultWildcardStr);
59 static const wxString wxPyEmptyString(wxT(""));
62 //---------------------------------------------------------------------------
65 wxString wxFileSelector(const wxString& message = wxPyFileSelectorPromptStr,
66 const wxString& default_path = wxPyEmptyString,
67 const wxString& default_filename = wxPyEmptyString,
68 const wxString& default_extension = wxPyEmptyString,
69 const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr,
71 wxWindow *parent = NULL,
72 int x = -1, int y = -1);
74 // Ask for filename to load
75 wxString wxLoadFileSelector(const wxString& what,
76 const wxString& extension,
77 const wxString& default_name = wxPyEmptyString,
78 wxWindow *parent = NULL);
80 // Ask for filename to save
81 wxString wxSaveFileSelector(const wxString& what,
82 const wxString& extension,
83 const wxString& default_name = wxPyEmptyString,
84 wxWindow *parent = NULL);
86 wxString wxGetTextFromUser(const wxString& message,
87 const wxString& caption = wxPyEmptyString,
88 const wxString& default_value = wxPyEmptyString,
89 wxWindow *parent = NULL,
90 int x = -1, int y = -1,
93 wxString wxGetPasswordFromUser(const wxString& message,
94 const wxString& caption = wxPyEmptyString,
95 const wxString& default_value = wxPyEmptyString,
96 wxWindow *parent = NULL);
99 // TODO: Need to custom wrap this one...
100 // int wxGetMultipleChoice(char* message, char* caption,
101 // int LCOUNT, char** choices,
102 // int nsel, int *selection,
103 // wxWindow *parent = NULL, int x = -1, int y = -1,
104 // bool centre = TRUE, int width=150, int height=200);
107 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
108 int LCOUNT, wxString* choices,
109 wxWindow *parent = NULL,
110 int x = -1, int y = -1,
112 int width=150, int height=200);
114 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
115 int LCOUNT, wxString* choices,
116 wxWindow *parent = NULL,
117 int x = -1, int y = -1,
119 int width=150, int height=200);
122 int wxMessageBox(const wxString& message,
123 const wxString& caption = wxPyEmptyString,
124 int style = wxOK | wxCENTRE,
125 wxWindow *parent = NULL,
126 int x = -1, int y = -1);
128 long wxGetNumberFromUser(const wxString& message,
129 const wxString& prompt,
130 const wxString& caption,
132 long min = 0, long max = 100,
133 wxWindow *parent = NULL,
134 const wxPoint& pos = wxDefaultPosition);
136 //---------------------------------------------------------------------------
139 bool wxColourDisplay();
141 int wxDisplayDepth();
142 int wxGetDisplayDepth();
144 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
145 wxSize wxGetDisplaySize();
147 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
148 wxSize wxGetDisplaySizeMM();
150 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
151 wxRect wxGetClientDisplayRect();
153 void wxSetCursor(wxCursor& cursor);
155 //----------------------------------------------------------------------
156 // Miscellaneous functions
158 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
159 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
161 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
162 wxWindow * wxGetActiveWindow();
164 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
165 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
168 bool wxCheckForInterrupt(wxWindow *wnd);
169 void wxFlushEvents();
172 //---------------------------------------------------------------------------
175 bool wxResourceAddIdentifier(char* name, int value);
176 void wxResourceClear(void);
177 wxBitmap wxResourceCreateBitmap(char* resource);
178 wxIcon wxResourceCreateIcon(char* resource);
179 wxMenuBar * wxResourceCreateMenuBar(char* resource);
180 int wxResourceGetIdentifier(char* name);
181 bool wxResourceParseData(char* resource, wxResourceTable *table = NULL);
182 bool wxResourceParseFile(char* filename, wxResourceTable *table = NULL);
183 bool wxResourceParseString(char* resource, wxResourceTable *table = NULL);
185 //---------------------------------------------------------------------------
188 // possible values for wxSystemSettings::GetFont() parameter
192 wxSYS_OEM_FIXED_FONT = 10,
193 wxSYS_ANSI_FIXED_FONT,
196 wxSYS_DEVICE_DEFAULT_FONT,
197 wxSYS_DEFAULT_PALETTE,
198 wxSYS_SYSTEM_FIXED_FONT,
199 wxSYS_DEFAULT_GUI_FONT
202 // possible values for wxSystemSettings::GetColour() parameter
206 wxSYS_COLOUR_SCROLLBAR,
207 wxSYS_COLOUR_BACKGROUND,
208 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
209 wxSYS_COLOUR_ACTIVECAPTION,
210 wxSYS_COLOUR_INACTIVECAPTION,
213 wxSYS_COLOUR_WINDOWFRAME,
214 wxSYS_COLOUR_MENUTEXT,
215 wxSYS_COLOUR_WINDOWTEXT,
216 wxSYS_COLOUR_CAPTIONTEXT,
217 wxSYS_COLOUR_ACTIVEBORDER,
218 wxSYS_COLOUR_INACTIVEBORDER,
219 wxSYS_COLOUR_APPWORKSPACE,
220 wxSYS_COLOUR_HIGHLIGHT,
221 wxSYS_COLOUR_HIGHLIGHTTEXT,
222 wxSYS_COLOUR_BTNFACE,
223 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
224 wxSYS_COLOUR_BTNSHADOW,
225 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
226 wxSYS_COLOUR_GRAYTEXT,
227 wxSYS_COLOUR_BTNTEXT,
228 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
229 wxSYS_COLOUR_BTNHIGHLIGHT,
230 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
231 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
232 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
233 wxSYS_COLOUR_3DDKSHADOW,
234 wxSYS_COLOUR_3DLIGHT,
235 wxSYS_COLOUR_INFOTEXT,
237 wxSYS_COLOUR_LISTBOX,
238 wxSYS_COLOUR_HOTLIGHT,
239 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
240 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
241 wxSYS_COLOUR_MENUHILIGHT,
242 wxSYS_COLOUR_MENUBAR,
247 // possible values for wxSystemSettings::GetMetric() parameter
251 wxSYS_MOUSE_BUTTONS = 1,
262 wxSYS_HSCROLL_ARROW_X,
263 wxSYS_HSCROLL_ARROW_Y,
279 wxSYS_VSCROLL_ARROW_X,
280 wxSYS_VSCROLL_ARROW_Y,
284 wxSYS_NETWORK_PRESENT,
285 wxSYS_PENWINDOWS_PRESENT,
290 // possible values for wxSystemSettings::HasFeature() parameter
293 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
294 wxSYS_CAN_ICONIZE_FRAME
299 class wxSystemSettings {
301 // get a standard system colour
302 static wxColour GetColour(wxSystemColour index);
304 // get a standard system font
305 static wxFont GetFont(wxSystemFont index);
307 // get a system-dependent metric
308 static int GetMetric(wxSystemMetric index);
310 // return true if the port has certain feature
311 static bool HasFeature(wxSystemFeature index);
317 //---------------------------------------------------------------------------
320 class wxToolTip : public wxObject {
322 wxToolTip(const wxString &tip);
324 void SetTip(const wxString& tip);
326 // *** Not in the "public" interface void SetWindow(wxWindow *win);
327 wxWindow *GetWindow();
329 static void Enable(bool flag);
330 static void SetDelay(long milliseconds);
333 //----------------------------------------------------------------------
337 wxCaret(wxWindow* window, const wxSize& size);
342 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
343 wxPoint GetPosition();
344 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
346 wxWindow *GetWindow();
347 %name(MoveXY)void Move(int x, int y);
348 void Move(const wxPoint& pt);
349 %name(SetSizeWH) void SetSize(int width, int height);
350 void SetSize(const wxSize& size);
351 void Show(int show = TRUE);
356 int wxCaret_GetBlinkTime() {
357 return wxCaret::GetBlinkTime();
360 void wxCaret_SetBlinkTime(int milliseconds) {
361 wxCaret::SetBlinkTime(milliseconds);
365 //----------------------------------------------------------------------
369 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
373 //----------------------------------------------------------------------
375 class wxWindowDisabler {
377 wxWindowDisabler(wxWindow *winToSkip = NULL);
381 //----------------------------------------------------------------------
383 bool wxSafeYield(wxWindow* win=NULL);
384 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
389 void wxWakeUpMainThread();
392 void wxMutexGuiEnter();
393 void wxMutexGuiLeave();
396 class wxMutexGuiLocker {
404 bool wxThread_IsMain() {
405 #ifdef WXP_WITH_THREAD
406 return wxThread::IsMain();
413 //----------------------------------------------------------------------
419 // wxTipProvider(size_t currentTip); **** Abstract base class
422 virtual wxString GetTip() = 0;
423 size_t GetCurrentTip();
428 // The C++ version of wxPyTipProvider
430 class wxPyTipProvider : public wxTipProvider {
432 wxPyTipProvider(size_t currentTip)
433 : wxTipProvider(currentTip) {}
435 DEC_PYCALLBACK_STRING__pure(GetTip);
440 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
445 // Now let SWIG know about it
446 class wxPyTipProvider : public wxTipProvider {
448 wxPyTipProvider(size_t currentTip);
453 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
454 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
457 //----------------------------------------------------------------------
460 #include <wx/generic/dragimgg.h>
463 %name (wxDragImage) class wxGenericDragImage : public wxObject
467 wxGenericDragImage(const wxBitmap& image,
468 const wxCursor& cursor = wxNullCursor);
469 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
470 const wxCursor& cursor = wxNullCursor);
471 %name(wxDragString)wxGenericDragImage(const wxString& str,
472 const wxCursor& cursor = wxNullCursor);
473 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
474 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
476 ~wxGenericDragImage();
478 void SetBackingBitmap(wxBitmap* bitmap);
479 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
480 bool fullScreen = FALSE, wxRect* rect = NULL);
482 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
483 wxWindow* fullScreenRect);
486 bool Move(const wxPoint& pt);
490 wxRect GetImageRect(const wxPoint& pos) const;
491 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
492 bool eraseOld, bool drawNew);
496 //----------------------------------------------------------------------
498 class wxPyTimer : public wxObject {
500 wxPyTimer(PyObject* notify);
505 void SetOwner(wxEvtHandler *owner, int id = -1);
506 void Start(int milliseconds=-1, int oneShot=FALSE);
514 // ctor starts the stop watch
517 void Start(long t = 0);
521 // get elapsed time since the last Start() or Pause() in milliseconds
526 //----------------------------------------------------------------------
527 //----------------------------------------------------------------------
532 wxLOG_FatalError, // program can't continue, abort immediately
533 wxLOG_Error, // a serious error, user must be informed about it
534 wxLOG_Warning, // user is normally informed about it but may be ignored
535 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
536 wxLOG_Info, // informational message (a.k.a. 'Verbose')
537 wxLOG_Status, // informational: might go to the status line of GUI app
538 wxLOG_Debug, // never shown to the user, disabled in release mode
539 wxLOG_Trace, // trace messages are also only enabled in debug mode
540 wxLOG_Progress, // used for progress indicator (not yet)
541 wxLOG_User = 100 // user defined levels start here
550 static bool IsEnabled();
551 static bool EnableLogging(bool doIt = TRUE);
552 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
554 virtual void Flush();
555 bool HasPendingMessages() const;
557 static void FlushActive();
558 static wxLog *GetActiveTarget();
559 static wxLog *SetActiveTarget(wxLog *pLogger);
561 static void Suspend();
562 static void Resume();
564 static void SetVerbose(bool bVerbose = TRUE);
566 static void DontCreateOnDemand();
567 static void SetTraceMask(wxTraceMask ulMask);
568 static void AddTraceMask(const wxString& str);
569 static void RemoveTraceMask(const wxString& str);
570 static void ClearTraceMasks();
572 static void SetTimestamp(const wxString& ts);
573 static const wxString& GetTimestamp();
575 bool GetVerbose() const { return m_bVerbose; }
577 static wxTraceMask GetTraceMask();
578 static bool IsAllowedTraceMask(const wxString& mask);
580 // static void TimeStamp(wxString *str);
582 wxString TimeStamp() {
584 wxLog::TimeStamp(&msg);
592 class wxLogStderr : public wxLog
595 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
599 class wxLogTextCtrl : public wxLog
602 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
606 class wxLogGui : public wxLog
612 class wxLogWindow : public wxLog
615 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
616 const wxString& szTitle, // the title of the frame
617 bool bShow = TRUE, // show window immediately?
618 bool bPassToOld = TRUE); // pass log messages to the old target?
620 void Show(bool bShow = TRUE);
621 wxFrame *GetFrame() const;
622 wxLog *GetOldLog() const;
623 bool IsPassingMessages() const;
624 void PassMessages(bool bDoPass);
636 class wxLogChain : public wxLog
639 wxLogChain(wxLog *logger);
640 void SetLog(wxLog *logger);
641 void PassMessages(bool bDoPass);
642 bool IsPassingMessages();
647 unsigned long wxSysErrorCode();
648 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
649 void wxLogFatalError(const wxString& szFormat);
650 void wxLogError(const wxString& szFormat);
651 void wxLogWarning(const wxString& szFormat);
652 void wxLogMessage(const wxString& szFormat);
653 void wxLogInfo(const wxString& szFormat);
654 void wxLogVerbose(const wxString& szFormat);
655 void wxLogStatus(const wxString& szFormat);
656 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
657 void wxLogSysError(const wxString& szFormat);
661 // A Log class that can be derived from in wxPython
662 class wxPyLog : public wxLog {
664 wxPyLog() : wxLog() {}
666 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
668 wxPyBeginBlockThreads();
669 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
670 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
671 wx2PyString(szString), t));
672 wxPyEndBlockThreads();
674 wxLog::DoLog(level, szString, t);
677 virtual void DoLogString(const wxChar *szString, time_t t) {
679 wxPyBeginBlockThreads();
680 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
681 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
682 wx2PyString(szString), t));
683 wxPyEndBlockThreads();
685 wxLog::DoLogString(szString, t);
692 // Now tell SWIG about it
693 class wxPyLog : public wxLog {
696 void _setCallbackInfo(PyObject* self, PyObject* _class);
697 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
698 %addmethods { void Destroy() { delete self; } }
703 //----------------------------------------------------------------------
712 class wxProcessEvent : public wxEvent {
714 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
717 int m_pid, m_exitcode;
723 %{ // C++ version of wxProcess derived class
725 class wxPyProcess : public wxProcess {
727 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
728 : wxProcess(parent, id)
731 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
736 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
741 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
743 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
744 %addmethods { void Destroy() { delete self; } }
746 void _setCallbackInfo(PyObject* self, PyObject* _class);
747 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
749 void base_OnTerminate(int pid, int status);
755 wxInputStream *GetInputStream();
756 wxInputStream *GetErrorStream();
757 wxOutputStream *GetOutputStream();
765 // execute the process asynchronously
768 // execute it synchronously, i.e. wait until it finishes
771 // under Windows, don't hide the child even if it's IO is redirected (this
772 // is done by default)
775 // under Unix, if the process is the group leader then killing -pid kills
776 // all children as well as pid
777 wxEXEC_MAKE_GROUP_LEADER = 4
781 long wxExecute(const wxString& command,
782 int flags = wxEXEC_ASYNC,
783 wxPyProcess *process = NULL);
785 //----------------------------------------------------------------------
788 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
789 // A C++ stub class for wxJoystick for platforms that don't have it.
790 class wxJoystick : public wxObject {
792 wxJoystick(int joystick = wxJOYSTICK1) {
793 wxPyBeginBlockThreads();
794 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
795 wxPyEndBlockThreads();
797 wxPoint GetPosition() { return wxPoint(-1,-1); }
798 int GetZPosition() { return -1; }
799 int GetButtonState() { return -1; }
800 int GetPOVPosition() { return -1; }
801 int GetPOVCTSPosition() { return -1; }
802 int GetRudderPosition() { return -1; }
803 int GetUPosition() { return -1; }
804 int GetVPosition() { return -1; }
805 int GetMovementThreshold() { return -1; }
806 void SetMovementThreshold(int threshold) {}
808 bool IsOk(void) { return FALSE; }
809 int GetNumberJoysticks() { return -1; }
810 int GetManufacturerId() { return -1; }
811 int GetProductId() { return -1; }
812 wxString GetProductName() { return ""; }
813 int GetXMin() { return -1; }
814 int GetYMin() { return -1; }
815 int GetZMin() { return -1; }
816 int GetXMax() { return -1; }
817 int GetYMax() { return -1; }
818 int GetZMax() { return -1; }
819 int GetNumberButtons() { return -1; }
820 int GetNumberAxes() { return -1; }
821 int GetMaxButtons() { return -1; }
822 int GetMaxAxes() { return -1; }
823 int GetPollingMin() { return -1; }
824 int GetPollingMax() { return -1; }
825 int GetRudderMin() { return -1; }
826 int GetRudderMax() { return -1; }
827 int GetUMin() { return -1; }
828 int GetUMax() { return -1; }
829 int GetVMin() { return -1; }
830 int GetVMax() { return -1; }
832 bool HasRudder() { return FALSE; }
833 bool HasZ() { return FALSE; }
834 bool HasU() { return FALSE; }
835 bool HasV() { return FALSE; }
836 bool HasPOV() { return FALSE; }
837 bool HasPOV4Dir() { return FALSE; }
838 bool HasPOVCTS() { return FALSE; }
840 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
841 bool ReleaseCapture() { return FALSE; }
847 class wxJoystick : public wxObject {
849 wxJoystick(int joystick = wxJOYSTICK1);
852 wxPoint GetPosition();
854 int GetButtonState();
855 int GetPOVPosition();
856 int GetPOVCTSPosition();
857 int GetRudderPosition();
860 int GetMovementThreshold();
861 void SetMovementThreshold(int threshold) ;
864 int GetNumberJoysticks();
865 int GetManufacturerId();
867 wxString GetProductName();
874 int GetNumberButtons();
895 bool SetCapture(wxWindow* win, int pollingFreq = 0);
896 bool ReleaseCapture();
899 //----------------------------------------------------------------------
903 // A C++ stub class for wxWave for platforms that don't have it.
904 class wxWave : public wxObject
907 wxWave(const wxString& fileName, bool isResource = FALSE) {
908 wxPyBeginBlockThreads();
909 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
910 wxPyEndBlockThreads();
912 wxWave(int size, const wxByte* data) {
913 wxPyBeginBlockThreads();
914 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
915 wxPyEndBlockThreads();
920 bool IsOk() const { return FALSE; }
921 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
927 class wxWave : public wxObject
930 wxWave(const wxString& fileName, bool isResource = FALSE);
934 bool Play(bool async = TRUE, bool looped = FALSE) const;
937 %new wxWave* wxWaveData(const wxString& data);
938 %{ // Implementations of some alternate "constructors"
939 wxWave* wxWaveData(const wxString& data) {
940 return new wxWave(data.Len(), (wxByte*)data.c_str());
945 //----------------------------------------------------------------------
949 wxMAILCAP_STANDARD = 1,
950 wxMAILCAP_NETSCAPE = 2,
964 wxFileTypeInfo(const char* mimeType,
966 const char* printCmd,
970 // the array elements correspond to the parameters of the ctor above in
972 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
974 // invalid item - use this to terminate the array passed to
975 // wxMimeTypesManager::AddFallbacks
976 %name(wxNullFileTypeInfo)wxFileTypeInfo();
979 // test if this object can be used
980 bool IsValid() const;
984 void SetIcon(const wxString& iconFile, int iconIndex = 0);
986 // set the short desc
987 void SetShortDesc(const wxString& shortDesc);
991 const wxString& GetMimeType() const;
992 // get the open command
993 const wxString& GetOpenCommand() const;
994 // get the print command
995 const wxString& GetPrintCommand() const;
996 // get the short description (only used under Win32 so far)
997 const wxString& GetShortDesc() const;
998 // get the long, user visible description
999 const wxString& GetDescription() const;
1002 // get the array of all extensions
1003 //const wxArrayString& GetExtensions() const;
1005 PyObject* GetExtensions() {
1006 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1007 return wxArrayString2PyList_helper(arr);
1011 int GetExtensionsCount() const;
1013 // get the icon info
1014 const wxString& GetIconFile() const;
1015 int GetIconIndex() const;
1025 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1027 // An object of this class must be passed to Get{Open|Print}Command. The
1028 // default implementation is trivial and doesn't know anything at all about
1029 // parameters, only filename and MIME type are used (so it's probably ok for
1030 // Windows where %{param} is not used anyhow)
1031 class MessageParameters
1035 MessageParameters(const wxString& filename=wxPyEmptyString,
1036 const wxString& mimetype=wxPyEmptyString);
1038 // accessors (called by GetOpenCommand)
1040 const wxString& GetFileName() const;
1042 const wxString& GetMimeType() const;;
1044 // override this function in derived class
1045 virtual wxString GetParamValue(const wxString& name) const;
1047 // virtual dtor as in any base class
1048 virtual ~MessageParameters();
1052 // ctor from static data
1053 wxFileType(const wxFileTypeInfo& ftInfo);
1055 // return the MIME type for this file type
1057 PyObject* GetMimeType() {
1059 if (self->GetMimeType(&str)) {
1061 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1063 return PyString_FromStringAndSize(str.c_str(), str.Len());
1069 PyObject* GetMimeTypes() {
1071 if (self->GetMimeTypes(arr))
1072 return wxArrayString2PyList_helper(arr);
1079 // Get all extensions associated with this file type
1081 PyObject* GetExtensions() {
1083 if (self->GetExtensions(arr))
1084 return wxArrayString2PyList_helper(arr);
1092 // Get the icon corresponding to this file type
1093 %new wxIcon* GetIcon() {
1095 if (self->GetIcon(&icon))
1096 return new wxIcon(icon);
1101 // Get the icon corresponding to this file type, the name of the file
1102 // where this icon resides, and its index in this file if applicable.
1103 PyObject* GetIconInfo() {
1107 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1108 wxPyBeginBlockThreads();
1109 PyObject* tuple = PyTuple_New(3);
1110 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1113 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1115 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1117 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1118 wxPyEndBlockThreads();
1127 // get a brief file type description ("*.txt" => "text document")
1128 PyObject* GetDescription() {
1130 if (self->GetDescription(&str)) {
1132 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1134 return PyString_FromStringAndSize(str.c_str(), str.Len());
1142 // get the command to open/execute the file of given type
1144 PyObject* GetOpenCommand(const wxString& filename,
1145 const wxString& mimetype=wxPyEmptyString) {
1147 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1149 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1151 return PyString_FromStringAndSize(str.c_str(), str.Len());
1159 // get the command to print the file of given type
1161 PyObject* GetPrintCommand(const wxString& filename,
1162 const wxString& mimetype=wxPyEmptyString) {
1164 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1166 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1168 return PyString_FromStringAndSize(str.c_str(), str.Len());
1176 // Get all commands defined for this file type
1178 PyObject* GetAllCommands(const wxString& filename,
1179 const wxString& mimetype=wxPyEmptyString) {
1180 wxArrayString verbs;
1181 wxArrayString commands;
1182 if (self->GetAllCommands(&verbs, &commands,
1183 wxFileType::MessageParameters(filename, mimetype))) {
1184 wxPyBeginBlockThreads();
1185 PyObject* tuple = PyTuple_New(2);
1186 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1187 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1188 wxPyEndBlockThreads();
1197 // set an arbitrary command, ask confirmation if it already exists and
1198 // overwriteprompt is TRUE
1199 bool SetCommand(const wxString& cmd, const wxString& verb,
1200 bool overwriteprompt = TRUE);
1202 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
1205 // remove the association for this filetype from the system MIME database:
1206 // notice that it will only work if the association is defined in the user
1207 // file/registry part, we will never modify the system-wide settings
1211 // expand a string in the format of GetOpenCommand (which may contain
1212 // '%s' and '%t' format specificators for the file name and mime type
1213 // and %{param} constructions).
1214 static wxString ExpandCommand(const wxString& command,
1215 const MessageParameters& params);
1217 // dtor (not virtual, shouldn't be derived from)
1225 class wxMimeTypesManager
1228 // static helper functions
1229 // -----------------------
1231 // check if the given MIME type is the same as the other one: the
1232 // second argument may contain wildcards ('*'), but not the first. If
1233 // the types are equal or if the mimeType matches wildcard the function
1234 // returns TRUE, otherwise it returns FALSE
1235 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1238 wxMimeTypesManager();
1240 // loads data from standard files according to the mailcap styles
1241 // specified: this is a bitwise OR of wxMailcapStyle values
1243 // use the extraDir parameter if you want to look for files in another
1245 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1246 const wxString& extraDir = wxPyEmptyString);
1248 // and this function clears all the data from the manager
1251 // Database lookup: all functions return a pointer to wxFileType object
1252 // whose methods may be used to query it for the information you're
1253 // interested in. If the return value is !NULL, caller is responsible for
1255 // get file type from file extension
1256 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1258 // get file type from MIME type (in format <category>/<format>)
1259 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1261 // other operations: return TRUE if there were no errors or FALSE if there
1262 // were some unreckognized entries (the good entries are always read anyhow)
1265 // read in additional file (the standard ones are read automatically)
1266 // in mailcap format (see mimetype.cpp for description)
1268 // 'fallback' parameter may be set to TRUE to avoid overriding the
1269 // settings from other, previously parsed, files by this one: normally,
1270 // the files read most recently would override the older files, but with
1271 // fallback == TRUE this won't happen
1272 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1274 // read in additional file in mime.types format
1275 bool ReadMimeTypes(const wxString& filename);
1277 // enumerate all known MIME types
1279 PyObject* EnumAllFileTypes() {
1281 self->EnumAllFileTypes(arr);
1282 return wxArrayString2PyList_helper(arr);
1286 // these functions can be used to provide default values for some of the
1287 // MIME types inside the program itself (you may also use
1288 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1289 // achieve the same goal, but this requires having this info in a file).
1291 void AddFallback(const wxFileTypeInfo& ft);
1294 // create or remove associations
1296 // create a new association using the fields of wxFileTypeInfo (at least
1297 // the MIME type and the extension should be set)
1298 // if the other fields are empty, the existing values should be left alone
1299 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1302 bool Unassociate(wxFileType *ft) ;
1304 // dtor (not virtual, shouldn't be derived from)
1305 ~wxMimeTypesManager();
1313 extern wxMimeTypesManager* wxTheMimeTypesManager;
1319 //----------------------------------------------------------------------
1322 #include <wx/docview.h>
1325 class wxFileHistory : public wxObject
1328 wxFileHistory(int maxFiles = 9);
1332 void AddFileToHistory(const wxString& file);
1333 void RemoveFileFromHistory(int i);
1334 int GetMaxFiles() const;
1335 void UseMenu(wxMenu *menu);
1337 // Remove menu from the list (MDI child may be closing)
1338 void RemoveMenu(wxMenu *menu);
1340 void Load(wxConfigBase& config);
1341 void Save(wxConfigBase& config);
1343 void AddFilesToMenu();
1344 %name(AddFilesToThisMenu)void AddFilesToMenu(wxMenu* menu);
1347 wxString GetHistoryFile(int i) const;
1349 // A synonym for GetNoHistoryFiles
1350 int GetCount() const;
1351 int GetNoHistoryFiles() const;
1355 //----------------------------------------------------------------------
1356 //----------------------------------------------------------------------
1360 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1361 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1364 //----------------------------------------------------------------------