]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/misc2.i
More unicode related cleanup and fixes for wxPython
[wxWidgets.git] / wxPython / src / misc2.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: misc2.i
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.)
6 //
7 // Author: Robin Dunn
8 //
9 // Created: 18-June-1999
10 // RCS-ID: $Id$
11 // Copyright: (c) 1998 by Total Control Software
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
14
15 %module misc2
16
17 %{
18 #include "helpers.h"
19 #include "pyistream.h"
20 #include <wx/resource.h>
21 #include <wx/tooltip.h>
22 #include <wx/caret.h>
23 #include <wx/fontenum.h>
24 #include <wx/tipdlg.h>
25 #include <wx/process.h>
26
27 #if wxUSE_JOYSTICK || defined(__WXMSW__)
28 #include <wx/joystick.h>
29 #endif
30
31 #if wxUSE_WAVE || defined(__WXMSW__)
32 #include <wx/wave.h>
33 #endif
34
35 #include <wx/mimetype.h>
36 %}
37
38 //----------------------------------------------------------------------
39
40 %include typemaps.i
41 %include my_typemaps.i
42
43 // Import some definitions of other classes, etc.
44 %import _defs.i
45 %import windows.i
46 %import misc.i
47 %import gdi.i
48 %import events.i
49 %import streams.i
50 %import utils.i
51
52
53 //----------------------------------------------------------------------
54
55 %{
56 // Put some wx default wxChar* values into wxStrings.
57 DECLARE_DEF_STRING(FileSelectorPromptStr);
58 DECLARE_DEF_STRING(FileSelectorDefaultWildcardStr);
59
60 static const wxString wxPyEmptyString(wxT(""));
61 %}
62
63 //---------------------------------------------------------------------------
64 // Dialog Functions
65
66 wxString wxFileSelector(const wxString& message = wxPyFileSelectorPromptStr,
67 const wxString& default_path = wxPyEmptyString,
68 const wxString& default_filename = wxPyEmptyString,
69 const wxString& default_extension = wxPyEmptyString,
70 const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr,
71 int flags = 0,
72 wxWindow *parent = NULL,
73 int x = -1, int y = -1);
74
75 // Ask for filename to load
76 wxString wxLoadFileSelector(const wxString& what,
77 const wxString& extension,
78 const wxString& default_name = wxPyEmptyString,
79 wxWindow *parent = NULL);
80
81 // Ask for filename to save
82 wxString wxSaveFileSelector(const wxString& what,
83 const wxString& extension,
84 const wxString& default_name = wxPyEmptyString,
85 wxWindow *parent = NULL);
86
87 wxString wxGetTextFromUser(const wxString& message,
88 const wxString& caption = wxPyEmptyString,
89 const wxString& default_value = wxPyEmptyString,
90 wxWindow *parent = NULL,
91 int x = -1, int y = -1,
92 bool centre = TRUE);
93
94 wxString wxGetPasswordFromUser(const wxString& message,
95 const wxString& caption = wxPyEmptyString,
96 const wxString& default_value = wxPyEmptyString,
97 wxWindow *parent = NULL);
98
99
100 // TODO: Need to custom wrap this one...
101 // int wxGetMultipleChoice(char* message, char* caption,
102 // int LCOUNT, char** choices,
103 // int nsel, int *selection,
104 // wxWindow *parent = NULL, int x = -1, int y = -1,
105 // bool centre = TRUE, int width=150, int height=200);
106
107
108 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
109 int LCOUNT, wxString* choices,
110 wxWindow *parent = NULL,
111 int x = -1, int y = -1,
112 bool centre = TRUE,
113 int width=150, int height=200);
114
115 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
116 int LCOUNT, wxString* choices,
117 wxWindow *parent = NULL,
118 int x = -1, int y = -1,
119 bool centre = TRUE,
120 int width=150, int height=200);
121
122
123 int wxMessageBox(const wxString& message,
124 const wxString& caption = wxPyEmptyString,
125 int style = wxOK | wxCENTRE,
126 wxWindow *parent = NULL,
127 int x = -1, int y = -1);
128
129 long wxGetNumberFromUser(const wxString& message,
130 const wxString& prompt,
131 const wxString& caption,
132 long value,
133 long min = 0, long max = 100,
134 wxWindow *parent = NULL,
135 const wxPoint& pos = wxDefaultPosition);
136
137 //---------------------------------------------------------------------------
138 // GDI Functions
139
140 bool wxColourDisplay();
141
142 int wxDisplayDepth();
143 int wxGetDisplayDepth();
144
145 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
146 wxSize wxGetDisplaySize();
147
148 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
149 wxSize wxGetDisplaySizeMM();
150
151 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
152 wxRect wxGetClientDisplayRect();
153
154 void wxSetCursor(wxCursor& cursor);
155
156 //----------------------------------------------------------------------
157 // Miscellaneous functions
158
159 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
160 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
161
162 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
163 wxWindow * wxGetActiveWindow();
164
165 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
166 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
167
168 #ifdef __WXMSW__
169 bool wxCheckForInterrupt(wxWindow *wnd);
170 void wxFlushEvents();
171 #endif
172
173 //---------------------------------------------------------------------------
174 // Resource System
175
176 bool wxResourceAddIdentifier(char* name, int value);
177 void wxResourceClear(void);
178 wxBitmap wxResourceCreateBitmap(char* resource);
179 wxIcon wxResourceCreateIcon(char* resource);
180 wxMenuBar * wxResourceCreateMenuBar(char* resource);
181 int wxResourceGetIdentifier(char* name);
182 bool wxResourceParseData(char* resource, wxResourceTable *table = NULL);
183 bool wxResourceParseFile(char* filename, wxResourceTable *table = NULL);
184 bool wxResourceParseString(char* resource, wxResourceTable *table = NULL);
185
186 //---------------------------------------------------------------------------
187 // System Settings
188
189 // possible values for wxSystemSettings::GetFont() parameter
190 //
191 enum wxSystemFont
192 {
193 wxSYS_OEM_FIXED_FONT = 10,
194 wxSYS_ANSI_FIXED_FONT,
195 wxSYS_ANSI_VAR_FONT,
196 wxSYS_SYSTEM_FONT,
197 wxSYS_DEVICE_DEFAULT_FONT,
198 wxSYS_DEFAULT_PALETTE,
199 wxSYS_SYSTEM_FIXED_FONT,
200 wxSYS_DEFAULT_GUI_FONT
201 };
202
203 // possible values for wxSystemSettings::GetColour() parameter
204 //
205 enum wxSystemColour
206 {
207 wxSYS_COLOUR_SCROLLBAR,
208 wxSYS_COLOUR_BACKGROUND,
209 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
210 wxSYS_COLOUR_ACTIVECAPTION,
211 wxSYS_COLOUR_INACTIVECAPTION,
212 wxSYS_COLOUR_MENU,
213 wxSYS_COLOUR_WINDOW,
214 wxSYS_COLOUR_WINDOWFRAME,
215 wxSYS_COLOUR_MENUTEXT,
216 wxSYS_COLOUR_WINDOWTEXT,
217 wxSYS_COLOUR_CAPTIONTEXT,
218 wxSYS_COLOUR_ACTIVEBORDER,
219 wxSYS_COLOUR_INACTIVEBORDER,
220 wxSYS_COLOUR_APPWORKSPACE,
221 wxSYS_COLOUR_HIGHLIGHT,
222 wxSYS_COLOUR_HIGHLIGHTTEXT,
223 wxSYS_COLOUR_BTNFACE,
224 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
225 wxSYS_COLOUR_BTNSHADOW,
226 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
227 wxSYS_COLOUR_GRAYTEXT,
228 wxSYS_COLOUR_BTNTEXT,
229 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
230 wxSYS_COLOUR_BTNHIGHLIGHT,
231 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
232 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
233 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
234 wxSYS_COLOUR_3DDKSHADOW,
235 wxSYS_COLOUR_3DLIGHT,
236 wxSYS_COLOUR_INFOTEXT,
237 wxSYS_COLOUR_INFOBK,
238 wxSYS_COLOUR_LISTBOX,
239 wxSYS_COLOUR_HOTLIGHT,
240 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
241 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
242 wxSYS_COLOUR_MENUHILIGHT,
243 wxSYS_COLOUR_MENUBAR,
244
245 wxSYS_COLOUR_MAX
246 };
247
248 // possible values for wxSystemSettings::GetMetric() parameter
249 //
250 enum wxSystemMetric
251 {
252 wxSYS_MOUSE_BUTTONS = 1,
253 wxSYS_BORDER_X,
254 wxSYS_BORDER_Y,
255 wxSYS_CURSOR_X,
256 wxSYS_CURSOR_Y,
257 wxSYS_DCLICK_X,
258 wxSYS_DCLICK_Y,
259 wxSYS_DRAG_X,
260 wxSYS_DRAG_Y,
261 wxSYS_EDGE_X,
262 wxSYS_EDGE_Y,
263 wxSYS_HSCROLL_ARROW_X,
264 wxSYS_HSCROLL_ARROW_Y,
265 wxSYS_HTHUMB_X,
266 wxSYS_ICON_X,
267 wxSYS_ICON_Y,
268 wxSYS_ICONSPACING_X,
269 wxSYS_ICONSPACING_Y,
270 wxSYS_WINDOWMIN_X,
271 wxSYS_WINDOWMIN_Y,
272 wxSYS_SCREEN_X,
273 wxSYS_SCREEN_Y,
274 wxSYS_FRAMESIZE_X,
275 wxSYS_FRAMESIZE_Y,
276 wxSYS_SMALLICON_X,
277 wxSYS_SMALLICON_Y,
278 wxSYS_HSCROLL_Y,
279 wxSYS_VSCROLL_X,
280 wxSYS_VSCROLL_ARROW_X,
281 wxSYS_VSCROLL_ARROW_Y,
282 wxSYS_VTHUMB_Y,
283 wxSYS_CAPTION_Y,
284 wxSYS_MENU_Y,
285 wxSYS_NETWORK_PRESENT,
286 wxSYS_PENWINDOWS_PRESENT,
287 wxSYS_SHOW_SOUNDS,
288 wxSYS_SWAP_BUTTONS
289 };
290
291 // possible values for wxSystemSettings::HasFeature() parameter
292 enum wxSystemFeature
293 {
294 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
295 wxSYS_CAN_ICONIZE_FRAME
296 };
297
298
299
300 class wxSystemSettings {
301 public:
302 // get a standard system colour
303 static wxColour GetColour(wxSystemColour index);
304
305 // get a standard system font
306 static wxFont GetFont(wxSystemFont index);
307
308 // get a system-dependent metric
309 static int GetMetric(wxSystemMetric index);
310
311 // return true if the port has certain feature
312 static bool HasFeature(wxSystemFeature index);
313
314 };
315
316
317
318 //---------------------------------------------------------------------------
319 // wxToolTip
320
321 class wxToolTip : public wxObject {
322 public:
323 wxToolTip(const wxString &tip);
324
325 void SetTip(const wxString& tip);
326 wxString GetTip();
327 // *** Not in the "public" interface void SetWindow(wxWindow *win);
328 wxWindow *GetWindow();
329
330 static void Enable(bool flag);
331 static void SetDelay(long milliseconds);
332 };
333
334 //----------------------------------------------------------------------
335
336 class wxCaret {
337 public:
338 wxCaret(wxWindow* window, const wxSize& size);
339 ~wxCaret();
340
341 bool IsOk();
342 bool IsVisible();
343 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
344 wxPoint GetPosition();
345 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
346 wxSize GetSize();
347 wxWindow *GetWindow();
348 %name(MoveXY)void Move(int x, int y);
349 void Move(const wxPoint& pt);
350 %name(SetSizeWH) void SetSize(int width, int height);
351 void SetSize(const wxSize& size);
352 void Show(int show = TRUE);
353 void Hide();
354 };
355
356 %inline %{
357 int wxCaret_GetBlinkTime() {
358 return wxCaret::GetBlinkTime();
359 }
360
361 void wxCaret_SetBlinkTime(int milliseconds) {
362 wxCaret::SetBlinkTime(milliseconds);
363 }
364 %}
365
366 //----------------------------------------------------------------------
367
368 %{
369 class wxPyFontEnumerator : public wxFontEnumerator {
370 public:
371 wxPyFontEnumerator() {}
372 ~wxPyFontEnumerator() {}
373
374 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
375 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
376
377 PYPRIVATE;
378 };
379
380 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
381 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
382
383 %}
384
385 %name(wxFontEnumerator) class wxPyFontEnumerator {
386 public:
387 wxPyFontEnumerator();
388 ~wxPyFontEnumerator();
389 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
390 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
391
392 bool EnumerateFacenames(
393 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
394 bool fixedWidthOnly = FALSE);
395 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
396
397 //wxArrayString* GetEncodings();
398 //wxArrayString* GetFacenames();
399 %addmethods {
400 PyObject* GetEncodings() {
401 wxArrayString* arr = self->GetEncodings();
402 return wxArrayString2PyList_helper(*arr);
403 }
404
405 PyObject* GetFacenames() {
406 wxArrayString* arr = self->GetFacenames();
407 return wxArrayString2PyList_helper(*arr);
408 }
409 }
410 };
411
412 //----------------------------------------------------------------------
413
414 class wxBusyCursor {
415 public:
416 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
417 ~wxBusyCursor();
418 };
419
420 //----------------------------------------------------------------------
421
422 class wxWindowDisabler {
423 public:
424 wxWindowDisabler(wxWindow *winToSkip = NULL);
425 ~wxWindowDisabler();
426 };
427
428 //----------------------------------------------------------------------
429
430 bool wxSafeYield(wxWindow* win=NULL);
431 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
432 void wxWakeUpIdle();
433
434
435 #ifdef __WXMSW__
436 void wxWakeUpMainThread();
437 #endif
438
439 void wxMutexGuiEnter();
440 void wxMutexGuiLeave();
441
442
443 class wxMutexGuiLocker {
444 public:
445 wxMutexGuiLocker();
446 ~wxMutexGuiLocker();
447 };
448
449
450 %inline %{
451 bool wxThread_IsMain() {
452 #ifdef WXP_WITH_THREAD
453 return wxThread::IsMain();
454 #else
455 return TRUE;
456 #endif
457 }
458 %}
459
460 //----------------------------------------------------------------------
461
462
463 class wxTipProvider
464 {
465 public:
466 // wxTipProvider(size_t currentTip); **** Abstract base class
467 ~wxTipProvider();
468
469 virtual wxString GetTip() = 0;
470 size_t GetCurrentTip();
471
472 };
473
474
475 // The C++ version of wxPyTipProvider
476 %{
477 class wxPyTipProvider : public wxTipProvider {
478 public:
479 wxPyTipProvider(size_t currentTip)
480 : wxTipProvider(currentTip) {}
481
482 DEC_PYCALLBACK_STRING__pure(GetTip);
483
484 PYPRIVATE;
485 };
486
487 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
488
489 %}
490
491
492 // Now let SWIG know about it
493 class wxPyTipProvider : public wxTipProvider {
494 public:
495 wxPyTipProvider(size_t currentTip);
496 };
497
498
499
500 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
501 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
502
503
504 //----------------------------------------------------------------------
505
506 %{
507 #include <wx/generic/dragimgg.h>
508 %}
509
510 %name (wxDragImage) class wxGenericDragImage : public wxObject
511 {
512 public:
513
514 wxGenericDragImage(const wxBitmap& image,
515 const wxCursor& cursor = wxNullCursor);
516 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
517 const wxCursor& cursor = wxNullCursor);
518 %name(wxDragString)wxGenericDragImage(const wxString& str,
519 const wxCursor& cursor = wxNullCursor);
520 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
521 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
522
523 ~wxGenericDragImage();
524
525 void SetBackingBitmap(wxBitmap* bitmap);
526 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
527 bool fullScreen = FALSE, wxRect* rect = NULL);
528
529 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
530 wxWindow* fullScreenRect);
531
532 bool EndDrag();
533 bool Move(const wxPoint& pt);
534 bool Show();
535 bool Hide();
536
537 wxRect GetImageRect(const wxPoint& pos) const;
538 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
539 bool eraseOld, bool drawNew);
540 };
541
542
543 //----------------------------------------------------------------------
544
545 class wxPyTimer : public wxObject {
546 public:
547 wxPyTimer(PyObject* notify);
548 ~wxPyTimer();
549 int GetInterval();
550 bool IsOneShot();
551 bool IsRunning();
552 void SetOwner(wxEvtHandler *owner, int id = -1);
553 void Start(int milliseconds=-1, int oneShot=FALSE);
554 void Stop();
555 };
556
557
558 class wxStopWatch
559 {
560 public:
561 // ctor starts the stop watch
562 wxStopWatch();
563 ~wxStopWatch();
564 void Start(long t = 0);
565 void Pause();
566 void Resume();
567
568 // get elapsed time since the last Start() or Pause() in milliseconds
569 long Time() const;
570 };
571
572
573 //----------------------------------------------------------------------
574 //----------------------------------------------------------------------
575
576
577 enum
578 {
579 wxLOG_FatalError, // program can't continue, abort immediately
580 wxLOG_Error, // a serious error, user must be informed about it
581 wxLOG_Warning, // user is normally informed about it but may be ignored
582 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
583 wxLOG_Info, // informational message (a.k.a. 'Verbose')
584 wxLOG_Status, // informational: might go to the status line of GUI app
585 wxLOG_Debug, // never shown to the user, disabled in release mode
586 wxLOG_Trace, // trace messages are also only enabled in debug mode
587 wxLOG_Progress, // used for progress indicator (not yet)
588 wxLOG_User = 100 // user defined levels start here
589 };
590
591
592 class wxLog
593 {
594 public:
595 wxLog();
596
597 static bool IsEnabled();
598 static bool EnableLogging(bool doIt = TRUE);
599 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
600
601 virtual void Flush();
602 bool HasPendingMessages() const;
603
604 static void FlushActive();
605 static wxLog *GetActiveTarget();
606 static wxLog *SetActiveTarget(wxLog *pLogger);
607
608 static void Suspend();
609 static void Resume();
610
611 void SetVerbose(bool bVerbose = TRUE);
612
613 static void DontCreateOnDemand();
614 static void SetTraceMask(wxTraceMask ulMask);
615 static void AddTraceMask(const wxString& str);
616 static void RemoveTraceMask(const wxString& str);
617 static void ClearTraceMasks();
618
619 static void SetTimestamp(const wxString& ts);
620 static const wxString& GetTimestamp();
621
622 bool GetVerbose() const { return m_bVerbose; }
623
624 static wxTraceMask GetTraceMask();
625 static bool IsAllowedTraceMask(const wxString& mask);
626
627 // static void TimeStamp(wxString *str);
628 %addmethods {
629 wxString TimeStamp() {
630 wxString msg;
631 wxLog::TimeStamp(&msg);
632 return msg;
633 }
634 }
635 };
636
637
638 class wxLogStderr : public wxLog
639 {
640 public:
641 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
642 };
643
644
645 class wxLogTextCtrl : public wxLog
646 {
647 public:
648 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
649 };
650
651
652 class wxLogGui : public wxLog
653 {
654 public:
655 wxLogGui();
656 };
657
658 class wxLogWindow : public wxLog
659 {
660 public:
661 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
662 const wxString& szTitle, // the title of the frame
663 bool bShow = TRUE, // show window immediately?
664 bool bPassToOld = TRUE); // pass log messages to the old target?
665
666 void Show(bool bShow = TRUE);
667 wxFrame *GetFrame() const;
668 wxLog *GetOldLog() const;
669 bool IsPassingMessages() const;
670 void PassMessages(bool bDoPass);
671 };
672
673
674 class wxLogNull
675 {
676 public:
677 wxLogNull();
678 ~wxLogNull();
679 };
680
681
682 class wxLogChain : public wxLog
683 {
684 public:
685 wxLogChain(wxLog *logger);
686 void SetLog(wxLog *logger);
687 void PassMessages(bool bDoPass);
688 bool IsPassingMessages();
689 wxLog *GetOldLog();
690 };
691
692
693 unsigned long wxSysErrorCode();
694 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
695 void wxLogFatalError(const wxString& szFormat);
696 void wxLogError(const wxString& szFormat);
697 void wxLogWarning(const wxString& szFormat);
698 void wxLogMessage(const wxString& szFormat);
699 void wxLogInfo(const wxString& szFormat);
700 void wxLogVerbose(const wxString& szFormat);
701 void wxLogStatus(const wxString& szFormat);
702 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
703 void wxLogSysError(const wxString& szFormat);
704
705
706 %{
707 // A Log class that can be derived from in wxPython
708 class wxPyLog : public wxLog {
709 public:
710 wxPyLog() : wxLog() {}
711
712 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
713 bool found;
714 wxPyBeginBlockThreads();
715 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
716 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
717 wx2PyString(szString), t));
718 wxPyEndBlockThreads();
719 if (! found)
720 wxLog::DoLog(level, szString, t);
721 }
722
723 virtual void DoLogString(const wxChar *szString, time_t t) {
724 bool found;
725 wxPyBeginBlockThreads();
726 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
727 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
728 wx2PyString(szString), t));
729 wxPyEndBlockThreads();
730 if (! found)
731 wxLog::DoLogString(szString, t);
732 }
733
734 PYPRIVATE;
735 };
736 %}
737
738 // Now tell SWIG about it
739 class wxPyLog : public wxLog {
740 public:
741 wxPyLog();
742 void _setCallbackInfo(PyObject* self, PyObject* _class);
743 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
744 %addmethods { void Destroy() { delete self; } }
745
746 };
747
748
749 //----------------------------------------------------------------------
750
751
752 enum {
753 /* event type */
754 wxEVT_END_PROCESS
755 };
756
757
758 class wxProcessEvent : public wxEvent {
759 public:
760 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
761 int GetPid();
762 int GetExitCode();
763 int m_pid, m_exitcode;
764 };
765
766
767
768
769 %{ // C++ version of wxProcess derived class
770
771 class wxPyProcess : public wxProcess {
772 public:
773 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
774 : wxProcess(parent, id)
775 {}
776
777 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
778
779 PYPRIVATE;
780 };
781
782 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
783
784 %}
785
786
787 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
788 public:
789 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
790 %addmethods { void Destroy() { delete self; } }
791
792 void _setCallbackInfo(PyObject* self, PyObject* _class);
793 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
794
795 void base_OnTerminate(int pid, int status);
796
797 void Redirect();
798 bool IsRedirected();
799 void Detach();
800
801 wxInputStream *GetInputStream();
802 wxInputStream *GetErrorStream();
803 wxOutputStream *GetOutputStream();
804
805 void CloseOutput();
806 };
807
808
809
810 long wxExecute(const wxString& command,
811 int sync = FALSE,
812 wxPyProcess *process = NULL);
813
814 //----------------------------------------------------------------------
815
816 %{
817 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
818 // A C++ stub class for wxJoystick for platforms that don't have it.
819 class wxJoystick : public wxObject {
820 public:
821 wxJoystick(int joystick = wxJOYSTICK1) {
822 wxPyBeginBlockThreads();
823 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
824 wxPyEndBlockThreads();
825 }
826 wxPoint GetPosition() { return wxPoint(-1,-1); }
827 int GetZPosition() { return -1; }
828 int GetButtonState() { return -1; }
829 int GetPOVPosition() { return -1; }
830 int GetPOVCTSPosition() { return -1; }
831 int GetRudderPosition() { return -1; }
832 int GetUPosition() { return -1; }
833 int GetVPosition() { return -1; }
834 int GetMovementThreshold() { return -1; }
835 void SetMovementThreshold(int threshold) {}
836
837 bool IsOk(void) { return FALSE; }
838 int GetNumberJoysticks() { return -1; }
839 int GetManufacturerId() { return -1; }
840 int GetProductId() { return -1; }
841 wxString GetProductName() { return ""; }
842 int GetXMin() { return -1; }
843 int GetYMin() { return -1; }
844 int GetZMin() { return -1; }
845 int GetXMax() { return -1; }
846 int GetYMax() { return -1; }
847 int GetZMax() { return -1; }
848 int GetNumberButtons() { return -1; }
849 int GetNumberAxes() { return -1; }
850 int GetMaxButtons() { return -1; }
851 int GetMaxAxes() { return -1; }
852 int GetPollingMin() { return -1; }
853 int GetPollingMax() { return -1; }
854 int GetRudderMin() { return -1; }
855 int GetRudderMax() { return -1; }
856 int GetUMin() { return -1; }
857 int GetUMax() { return -1; }
858 int GetVMin() { return -1; }
859 int GetVMax() { return -1; }
860
861 bool HasRudder() { return FALSE; }
862 bool HasZ() { return FALSE; }
863 bool HasU() { return FALSE; }
864 bool HasV() { return FALSE; }
865 bool HasPOV() { return FALSE; }
866 bool HasPOV4Dir() { return FALSE; }
867 bool HasPOVCTS() { return FALSE; }
868
869 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
870 bool ReleaseCapture() { return FALSE; }
871 };
872 #endif
873 %}
874
875
876 class wxJoystick : public wxObject {
877 public:
878 wxJoystick(int joystick = wxJOYSTICK1);
879 ~wxJoystick();
880
881 wxPoint GetPosition();
882 int GetZPosition();
883 int GetButtonState();
884 int GetPOVPosition();
885 int GetPOVCTSPosition();
886 int GetRudderPosition();
887 int GetUPosition();
888 int GetVPosition();
889 int GetMovementThreshold();
890 void SetMovementThreshold(int threshold) ;
891
892 bool IsOk(void);
893 int GetNumberJoysticks();
894 int GetManufacturerId();
895 int GetProductId();
896 wxString GetProductName();
897 int GetXMin();
898 int GetYMin();
899 int GetZMin();
900 int GetXMax();
901 int GetYMax();
902 int GetZMax();
903 int GetNumberButtons();
904 int GetNumberAxes();
905 int GetMaxButtons();
906 int GetMaxAxes();
907 int GetPollingMin();
908 int GetPollingMax();
909 int GetRudderMin();
910 int GetRudderMax();
911 int GetUMin();
912 int GetUMax();
913 int GetVMin();
914 int GetVMax();
915
916 bool HasRudder();
917 bool HasZ();
918 bool HasU();
919 bool HasV();
920 bool HasPOV();
921 bool HasPOV4Dir();
922 bool HasPOVCTS();
923
924 bool SetCapture(wxWindow* win, int pollingFreq = 0);
925 bool ReleaseCapture();
926 };
927
928 //----------------------------------------------------------------------
929
930 %{
931 #if !wxUSE_WAVE
932 // A C++ stub class for wxWave for platforms that don't have it.
933 class wxWave : public wxObject
934 {
935 public:
936 wxWave(const wxString& fileName, bool isResource = FALSE) {
937 wxPyBeginBlockThreads();
938 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
939 wxPyEndBlockThreads();
940 }
941 wxWave(int size, const wxByte* data) {
942 wxPyBeginBlockThreads();
943 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
944 wxPyEndBlockThreads();
945 }
946
947 ~wxWave() {}
948
949 bool IsOk() const { return FALSE; }
950 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
951 };
952
953 #endif
954 %}
955
956 class wxWave : public wxObject
957 {
958 public:
959 wxWave(const wxString& fileName, bool isResource = FALSE);
960 ~wxWave();
961
962 bool IsOk() const;
963 bool Play(bool async = TRUE, bool looped = FALSE) const;
964 };
965
966 %new wxWave* wxWaveData(const wxString& data);
967 %{ // Implementations of some alternate "constructors"
968 wxWave* wxWaveData(const wxString& data) {
969 return new wxWave(data.Len(), (wxByte*)data.c_str());
970 }
971 %}
972
973
974 //----------------------------------------------------------------------
975
976 enum wxMailcapStyle
977 {
978 wxMAILCAP_STANDARD = 1,
979 wxMAILCAP_NETSCAPE = 2,
980 wxMAILCAP_KDE = 4,
981 wxMAILCAP_GNOME = 8,
982
983 wxMAILCAP_ALL = 15
984 };
985
986
987
988 class wxFileTypeInfo
989 {
990 public:
991 // ctors
992 // a normal item
993 wxFileTypeInfo(const char* mimeType,
994 const char* openCmd,
995 const char* printCmd,
996 const char* desc);
997
998
999 // the array elements correspond to the parameters of the ctor above in
1000 // the same order
1001 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
1002
1003 // invalid item - use this to terminate the array passed to
1004 // wxMimeTypesManager::AddFallbacks
1005 %name(wxNullFileTypeInfo)wxFileTypeInfo();
1006
1007
1008 // test if this object can be used
1009 bool IsValid() const;
1010
1011 // setters
1012 // set the icon info
1013 void SetIcon(const wxString& iconFile, int iconIndex = 0);
1014
1015 // set the short desc
1016 void SetShortDesc(const wxString& shortDesc);
1017
1018 // accessors
1019 // get the MIME type
1020 const wxString& GetMimeType() const;
1021 // get the open command
1022 const wxString& GetOpenCommand() const;
1023 // get the print command
1024 const wxString& GetPrintCommand() const;
1025 // get the short description (only used under Win32 so far)
1026 const wxString& GetShortDesc() const;
1027 // get the long, user visible description
1028 const wxString& GetDescription() const;
1029
1030
1031 // get the array of all extensions
1032 //const wxArrayString& GetExtensions() const;
1033 %addmethods {
1034 PyObject* GetExtensions() {
1035 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1036 return wxArrayString2PyList_helper(arr);
1037 }
1038 }
1039
1040 int GetExtensionsCount() const;
1041
1042 // get the icon info
1043 const wxString& GetIconFile() const;
1044 int GetIconIndex() const;
1045 };
1046
1047
1048
1049
1050 class wxFileType
1051 {
1052 public:
1053
1054 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1055
1056 // An object of this class must be passed to Get{Open|Print}Command. The
1057 // default implementation is trivial and doesn't know anything at all about
1058 // parameters, only filename and MIME type are used (so it's probably ok for
1059 // Windows where %{param} is not used anyhow)
1060 class MessageParameters
1061 {
1062 public:
1063 // ctors
1064 MessageParameters(const wxString& filename=wxPyEmptyString,
1065 const wxString& mimetype=wxPyEmptyString);
1066
1067 // accessors (called by GetOpenCommand)
1068 // filename
1069 const wxString& GetFileName() const;
1070 // mime type
1071 const wxString& GetMimeType() const;;
1072
1073 // override this function in derived class
1074 virtual wxString GetParamValue(const wxString& name) const;
1075
1076 // virtual dtor as in any base class
1077 virtual ~MessageParameters();
1078 };
1079
1080
1081 // ctor from static data
1082 wxFileType(const wxFileTypeInfo& ftInfo);
1083
1084 // return the MIME type for this file type
1085 %addmethods {
1086 PyObject* GetMimeType() {
1087 wxString str;
1088 if (self->GetMimeType(&str)) {
1089 #if wxUSE_UNICODE
1090 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1091 #else
1092 return PyString_FromStringAndSize(str.c_str(), str.Len());
1093 #endif
1094 }
1095 else
1096 RETURN_NONE();
1097 }
1098 PyObject* GetMimeTypes() {
1099 wxArrayString arr;
1100 if (self->GetMimeTypes(arr))
1101 return wxArrayString2PyList_helper(arr);
1102 else
1103 RETURN_NONE();
1104 }
1105 }
1106
1107
1108 // Get all extensions associated with this file type
1109 %addmethods {
1110 PyObject* GetExtensions() {
1111 wxArrayString arr;
1112 if (self->GetExtensions(arr))
1113 return wxArrayString2PyList_helper(arr);
1114 else
1115 RETURN_NONE();
1116 }
1117 }
1118
1119
1120 %addmethods {
1121 // Get the icon corresponding to this file type
1122 %new wxIcon* GetIcon() {
1123 wxIcon icon;
1124 if (self->GetIcon(&icon))
1125 return new wxIcon(icon);
1126 else
1127 return NULL;
1128 }
1129
1130 // Get the icon corresponding to this file type, the name of the file
1131 // where this icon resides, and its index in this file if applicable.
1132 PyObject* GetIconInfo() {
1133 wxIcon icon;
1134 wxString iconFile;
1135 int iconIndex;
1136 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1137 wxPyBeginBlockThreads();
1138 PyObject* tuple = PyTuple_New(3);
1139 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1140 "wxIcon", TRUE));
1141 #if wxUSE_UNICODE
1142 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1143 #else
1144 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1145 #endif
1146 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1147 wxPyEndBlockThreads();
1148 return tuple;
1149 }
1150 else
1151 RETURN_NONE();
1152 }
1153 }
1154
1155 %addmethods {
1156 // get a brief file type description ("*.txt" => "text document")
1157 PyObject* GetDescription() {
1158 wxString str;
1159 if (self->GetDescription(&str)) {
1160 #if wxUSE_UNICODE
1161 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1162 #else
1163 return PyString_FromStringAndSize(str.c_str(), str.Len());
1164 #endif
1165 } else
1166 RETURN_NONE();
1167 }
1168 }
1169
1170
1171 // get the command to open/execute the file of given type
1172 %addmethods {
1173 PyObject* GetOpenCommand(const wxString& filename,
1174 const wxString& mimetype=wxPyEmptyString) {
1175 wxString str;
1176 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1177 #if wxUSE_UNICODE
1178 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1179 #else
1180 return PyString_FromStringAndSize(str.c_str(), str.Len());
1181 #endif
1182 } else
1183 RETURN_NONE();
1184 }
1185 }
1186
1187
1188 // get the command to print the file of given type
1189 %addmethods {
1190 PyObject* GetPrintCommand(const wxString& filename,
1191 const wxString& mimetype=wxPyEmptyString) {
1192 wxString str;
1193 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1194 #if wxUSE_UNICODE
1195 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1196 #else
1197 return PyString_FromStringAndSize(str.c_str(), str.Len());
1198 #endif
1199 } else
1200 RETURN_NONE();
1201 }
1202 }
1203
1204
1205 // Get all commands defined for this file type
1206 %addmethods {
1207 PyObject* GetAllCommands(const wxString& filename,
1208 const wxString& mimetype=wxPyEmptyString) {
1209 wxArrayString verbs;
1210 wxArrayString commands;
1211 if (self->GetAllCommands(&verbs, &commands,
1212 wxFileType::MessageParameters(filename, mimetype))) {
1213 wxPyBeginBlockThreads();
1214 PyObject* tuple = PyTuple_New(2);
1215 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1216 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1217 wxPyEndBlockThreads();
1218 return tuple;
1219 }
1220 else
1221 RETURN_NONE();
1222 }
1223 }
1224
1225
1226 // set an arbitrary command, ask confirmation if it already exists and
1227 // overwriteprompt is TRUE
1228 bool SetCommand(const wxString& cmd, const wxString& verb,
1229 bool overwriteprompt = TRUE);
1230
1231 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
1232
1233
1234 // remove the association for this filetype from the system MIME database:
1235 // notice that it will only work if the association is defined in the user
1236 // file/registry part, we will never modify the system-wide settings
1237 bool Unassociate();
1238
1239 // operations
1240 // expand a string in the format of GetOpenCommand (which may contain
1241 // '%s' and '%t' format specificators for the file name and mime type
1242 // and %{param} constructions).
1243 static wxString ExpandCommand(const wxString& command,
1244 const MessageParameters& params);
1245
1246 // dtor (not virtual, shouldn't be derived from)
1247 ~wxFileType();
1248
1249 };
1250
1251
1252
1253
1254 class wxMimeTypesManager
1255 {
1256 public:
1257 // static helper functions
1258 // -----------------------
1259
1260 // check if the given MIME type is the same as the other one: the
1261 // second argument may contain wildcards ('*'), but not the first. If
1262 // the types are equal or if the mimeType matches wildcard the function
1263 // returns TRUE, otherwise it returns FALSE
1264 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1265
1266 // ctor
1267 wxMimeTypesManager();
1268
1269 // loads data from standard files according to the mailcap styles
1270 // specified: this is a bitwise OR of wxMailcapStyle values
1271 //
1272 // use the extraDir parameter if you want to look for files in another
1273 // directory
1274 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1275 const wxString& extraDir = wxPyEmptyString);
1276
1277 // and this function clears all the data from the manager
1278 void ClearData();
1279
1280 // Database lookup: all functions return a pointer to wxFileType object
1281 // whose methods may be used to query it for the information you're
1282 // interested in. If the return value is !NULL, caller is responsible for
1283 // deleting it.
1284 // get file type from file extension
1285 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1286
1287 // get file type from MIME type (in format <category>/<format>)
1288 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1289
1290 // other operations: return TRUE if there were no errors or FALSE if there
1291 // were some unreckognized entries (the good entries are always read anyhow)
1292 //
1293
1294 // read in additional file (the standard ones are read automatically)
1295 // in mailcap format (see mimetype.cpp for description)
1296 //
1297 // 'fallback' parameter may be set to TRUE to avoid overriding the
1298 // settings from other, previously parsed, files by this one: normally,
1299 // the files read most recently would override the older files, but with
1300 // fallback == TRUE this won't happen
1301 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1302
1303 // read in additional file in mime.types format
1304 bool ReadMimeTypes(const wxString& filename);
1305
1306 // enumerate all known MIME types
1307 %addmethods {
1308 PyObject* EnumAllFileTypes() {
1309 wxArrayString arr;
1310 self->EnumAllFileTypes(arr);
1311 return wxArrayString2PyList_helper(arr);
1312 }
1313 }
1314
1315 // these functions can be used to provide default values for some of the
1316 // MIME types inside the program itself (you may also use
1317 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1318 // achieve the same goal, but this requires having this info in a file).
1319 //
1320 void AddFallback(const wxFileTypeInfo& ft);
1321
1322
1323 // create or remove associations
1324
1325 // create a new association using the fields of wxFileTypeInfo (at least
1326 // the MIME type and the extension should be set)
1327 // if the other fields are empty, the existing values should be left alone
1328 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1329
1330 // undo Associate()
1331 bool Unassociate(wxFileType *ft) ;
1332
1333 // dtor (not virtual, shouldn't be derived from)
1334 ~wxMimeTypesManager();
1335 };
1336
1337
1338 %readonly
1339 %{
1340 #if 0
1341 %}
1342 extern wxMimeTypesManager* wxTheMimeTypesManager;
1343 %{
1344 #endif
1345 %}
1346 %readwrite
1347
1348 //----------------------------------------------------------------------
1349
1350 %{
1351 #include <wx/docview.h>
1352 %}
1353
1354 class wxFileHistory : public wxObject
1355 {
1356 public:
1357 wxFileHistory(int maxFiles = 9);
1358 ~wxFileHistory();
1359
1360 // Operations
1361 void AddFileToHistory(const wxString& file);
1362 void RemoveFileFromHistory(int i);
1363 int GetMaxFiles() const;
1364 void UseMenu(wxMenu *menu);
1365
1366 // Remove menu from the list (MDI child may be closing)
1367 void RemoveMenu(wxMenu *menu);
1368
1369 void Load(wxConfigBase& config);
1370 void Save(wxConfigBase& config);
1371
1372 void AddFilesToMenu();
1373 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1374
1375 // Accessors
1376 wxString GetHistoryFile(int i) const;
1377
1378 // A synonym for GetNoHistoryFiles
1379 int GetCount() const;
1380 int GetNoHistoryFiles() const;
1381
1382 };
1383
1384 //----------------------------------------------------------------------
1385 //----------------------------------------------------------------------
1386
1387
1388 %init %{
1389 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1390 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1391 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1392 %}
1393
1394 //----------------------------------------------------------------------
1395