Initial revision

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1998-05-20 14:01:55 +00:00
parent 1b66e7e5ab
commit c801d85f15
779 changed files with 172138 additions and 0 deletions

1
src/Makefile Normal file
View File

@@ -0,0 +1 @@
include gtk/setup/general/makeapp

183
src/Makefile.in Normal file
View File

@@ -0,0 +1,183 @@
#
# wxGTK main source makefile
#
# Copyright 1998, Markus Holzhem and Robert Roebling
#
# wxGTK base directory
WXBASEDIR=@WXBASEDIR@
# set the OS type for compilation
OS=@OS@
# compile a library only
RULE=gslib
# define common stuff
# needed for unactivated
NONE =
# define library name
LIB_TARGET=wx_gtk
LIB_MAJOR=0
LIB_MINOR=12
# define library sources
LIB_CPP_SRC=\
\
common/cmndata.cpp \
common/config.cpp \
common/date.cpp \
common/docview.cpp \
common/dynarray.cpp \
common/event.cpp \
common/file.cpp \
common/fileconf.cpp \
common/filefn.cpp \
common/gdicmn.cpp \
common/hash.cpp \
common/helpbase.cpp \
common/intl.cpp \
common/ipcbase.cpp \
common/layout.cpp \
common/list.cpp \
common/log.cpp \
common/matrix.cpp \
common/memory.cpp \
common/module.cpp \
common/object.cpp \
common/postscrp.cpp \
common/prntbase.cpp \
common/string.cpp \
common/textfile.cpp \
common/time.cpp \
common/timercmn.cpp \
common/utilscmn.cpp \
\
gtk/app.cpp \
gtk/bitmap.cpp \
gtk/brush.cpp \
gtk/button.cpp \
gtk/checkbox.cpp \
gtk/choice.cpp \
gtk/colour.cpp \
gtk/control.cpp \
gtk/cursor.cpp \
gtk/data.cpp \
gtk/dc.cpp \
gtk/dcclient.cpp \
gtk/dcmemory.cpp \
gtk/dcscreen.cpp \
gtk/dnd.cpp \
gtk/dialog.cpp \
gtk/filedlg.cpp \
gtk/font.cpp \
gtk/frame.cpp \
gtk/gdiobj.cpp \
gtk/icon.cpp \
gtk/listbox.cpp \
gtk/mdi.cpp \
gtk/menu.cpp \
gtk/palette.cpp \
gtk/pen.cpp \
gtk/radiobox.cpp \
gtk/radiobut.cpp \
gtk/region.cpp \
gtk/scrolbar.cpp \
gtk/settings.cpp \
gtk/slider.cpp \
gtk/statbox.cpp \
gtk/stattext.cpp \
gtk/tbargtk.cpp \
gtk/textctrl.cpp \
gtk/timer.cpp \
gtk/utilsgtk.cpp \
gtk/utilsres.cpp \
gtk/window.cpp \
\
generic/choicdgg.cpp \
generic/colrdlgg.cpp \
generic/fontdlgg.cpp \
generic/gridg.cpp \
generic/imaglist.cpp \
generic/listctrl.cpp \
generic/msgdlgg.cpp \
generic/panelg.cpp \
generic/printps.cpp \
generic/prntdlgg.cpp \
generic/scrolwin.cpp \
generic/splitter.cpp \
generic/statusbr.cpp \
generic/tabg.cpp \
generic/textdlgg.cpp \
generic/treectrl.cpp
LIB_C_SRC=\
\
gtk/win_gtk.c \
\
png/png.c \
png/pngset.c \
png/pngget.c \
png/pngrutil.c \
png/pngtrans.c \
png/pngwutil.c \
png/pngread.c \
png/pngrio.c \
png/pngwio.c \
png/pngwrite.c \
png/pngrtran.c \
png/pngwtran.c \
png/pngmem.c \
png/pngerror.c \
png/pngpread.c \
\
zlib/adler32.c \
zlib/compress.c \
zlib/crc32.c \
zlib/gzio.c \
zlib/uncompr.c \
zlib/deflate.c \
zlib/trees.c \
zlib/zutil.c \
zlib/inflate.c \
zlib/infblock.c \
zlib/inftrees.c \
zlib/infcodes.c \
zlib/infutil.c \
zlib/inffast.c \
\
gdk_imlib/cache.c \
gdk_imlib/colors.c \
gdk_imlib/globals.c \
gdk_imlib/load.c \
gdk_imlib/misc.c \
gdk_imlib/rend.c \
gdk_imlib/save.c \
gdk_imlib/utils.c
#define library objects
LIB_OBJ=\
$(LIB_CPP_SRC:.cpp=.o) \
$(LIB_C_SRC:.c=.o)
all::
-../mkdirs
clean::
$(RM) -rf gtk
$(RM) -rf common
$(RM) -rf generic
$(RM) -rf png
$(RM) -rf zlib
$(RM) -rf gdk_imlib
#additional things needed for compile
ADD_COMPILE= \
-DHAVE_LIBPNG -DDJPEG_PROG=\"\" -DCJPEG_PROG=\"\"
# include the definitions now
include ../../template.mak

473
src/common/cmndata.cpp Normal file
View File

@@ -0,0 +1,473 @@
/////////////////////////////////////////////////////////////////////////////
// Name: cmndata.cpp
// Purpose: Common GDI data
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "cmndata.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/utils.h"
#include "wx/app.h"
#endif
#include "wx/gdicmn.h"
#include "wx/cmndata.h"
#ifdef __WINDOWS__
#include <windows.h>
#ifndef __WIN32__
#include <print.h>
#include <commdlg.h>
#endif
#endif
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
#endif
/*
* wxColourData
*/
wxColourData::wxColourData(void)
{
int i;
for (i = 0; i < 16; i++)
custColours[i].Set(255, 255, 255);
chooseFull = FALSE;
dataColour.Set(0,0,0);
}
wxColourData::~wxColourData(void)
{
}
void wxColourData::SetCustomColour(int i, wxColour& colour)
{
if (i > 15 || i < 0)
return;
custColours[i] = colour;
}
wxColour wxColourData::GetCustomColour(int i)
{
if (i > 15 || i < 0)
return wxColour(0,0,0);
return custColours[i];
}
void wxColourData::operator=(const wxColourData& data)
{
int i;
for (i = 0; i < 16; i++)
custColours[i] = data.custColours[i];
dataColour = (wxColour&)data.dataColour;
chooseFull = data.chooseFull;
}
/*
* Font data
*/
wxFontData::wxFontData(void)
{
// Intialize colour to black.
fontColour.Set(0, 0, 0);
showHelp = FALSE;
allowSymbols = TRUE;
enableEffects = TRUE;
minSize = 0;
maxSize = 0;
}
wxFontData::~wxFontData(void)
{
}
void wxFontData::operator=(const wxFontData& data)
{
fontColour = data.fontColour;
showHelp = data.showHelp;
allowSymbols = data.allowSymbols;
enableEffects = data.enableEffects;
initialFont = data.initialFont;
chosenFont = data.chosenFont;
minSize = data.minSize;
maxSize = data.maxSize;
}
/*
* Print data
*/
wxPrintData::wxPrintData(void)
{
#ifdef __WINDOWS__
printData = NULL;
#endif
printOrientation = wxPORTRAIT;
printFromPage = 0;
printToPage = 0;
printMinPage = 0;
printMaxPage = 0;
printNoCopies = 1;
printAllPages = FALSE;
printCollate = FALSE;
printToFile = FALSE;
printEnableSelection = FALSE;
printEnablePageNumbers = TRUE;
printEnablePrintToFile = TRUE;
printEnableHelp = FALSE;
printSetupDialog = FALSE;
}
wxPrintData::~wxPrintData(void)
{
#ifdef __WINDOWS__
PRINTDLG *pd = (PRINTDLG *)printData;
if ( pd && pd->hDevMode )
GlobalFree(pd->hDevMode);
if ( pd )
delete pd;
#endif
}
#ifdef __WINDOWS__
void wxPrintData::ConvertToNative(void)
{
PRINTDLG *pd = (PRINTDLG*) printData;
if ( pd == NULL )
{
pd = new PRINTDLG;
printData = (void*) pd;
// GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
// pd->lStructSize = sizeof(PRINTDLG);
pd->lStructSize = 66 ;
pd->hwndOwner = (HWND)NULL;
pd->hDevMode = NULL; // Will be created by PrintDlg
pd->hDevNames = NULL; // Ditto
// Why had I put this #ifdef in?? Seems fine to me.
#if 1
pd->Flags = PD_RETURNDEFAULT;
pd->nCopies = 1;
// Fill out the DEVMODE structure
// so we can use it as input in the 'real' PrintDlg
if (!PrintDlg(pd))
{
if ( pd->hDevMode )
GlobalFree(pd->hDevMode);
if ( pd->hDevNames )
GlobalFree(pd->hDevNames);
pd->hDevMode = NULL;
pd->hDevNames = NULL;
}
else
{
if ( pd->hDevNames )
GlobalFree(pd->hDevNames);
pd->hDevNames = NULL;
}
#endif
}
if ( pd->hDevMode )
{
DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
devMode->dmOrientation = printOrientation;
devMode->dmFields = DM_ORIENTATION;
GlobalUnlock(pd->hDevMode);
}
pd->hDC = (HDC) NULL;
pd->nFromPage = (UINT)printFromPage;
pd->nToPage = (UINT)printToPage;
pd->nMinPage = (UINT)printMinPage;
pd->nMaxPage = (UINT)printMaxPage;
pd->nCopies = (UINT)printNoCopies;
pd->Flags = PD_RETURNDC ;
// pd->lStructSize = sizeof( PRINTDLG );
pd->lStructSize = 66 ;
pd->hwndOwner=(HANDLE)NULL;
pd->hDevNames=(HANDLE)NULL;
pd->hInstance=(HINSTANCE)NULL;
pd->lCustData = (LPARAM) NULL;
pd->lpfnPrintHook = NULL;
pd->lpfnSetupHook = NULL;
pd->lpPrintTemplateName = NULL;
pd->lpSetupTemplateName = NULL;
pd->hPrintTemplate = (HGLOBAL) NULL;
pd->hSetupTemplate = (HGLOBAL) NULL;
if ( printAllPages )
pd->Flags |= PD_ALLPAGES;
if ( printCollate )
pd->Flags |= PD_COLLATE;
if ( printToFile )
pd->Flags |= PD_PRINTTOFILE;
if ( !printEnablePrintToFile )
pd->Flags |= PD_DISABLEPRINTTOFILE;
if ( !printEnableSelection )
pd->Flags |= PD_NOSELECTION;
if ( !printEnablePageNumbers )
pd->Flags |= PD_NOPAGENUMS;
if ( printEnableHelp )
pd->Flags |= PD_SHOWHELP;
if ( printSetupDialog )
pd->Flags |= PD_PRINTSETUP;
}
void wxPrintData::ConvertFromNative(void)
{
PRINTDLG *pd = (PRINTDLG*) printData;
if ( pd == NULL )
return;
if ( pd->hDevMode )
{
DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
printOrientation = devMode->dmOrientation;
GlobalUnlock(pd->hDevMode);
}
printFromPage = pd->nFromPage ;
printToPage = pd->nToPage ;
printMinPage = pd->nMinPage ;
printMaxPage = pd->nMaxPage ;
printNoCopies = pd->nCopies ;
printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
}
void wxPrintData::SetOwnerWindow(wxWindow* win)
{
if ( printData == NULL )
ConvertToNative();
if ( printData != NULL && win != NULL)
{
PRINTDLG *pd = (PRINTDLG *) printData ;
pd->hwndOwner=(HWND) win->GetHWND();
}
}
#endif
void wxPrintData::operator=(const wxPrintData& data)
{
printFromPage = data.printFromPage;
printToPage = data.printToPage;
printMinPage = data.printMinPage;
printMaxPage = data.printMaxPage;
printNoCopies = data.printNoCopies;
printAllPages = data.printAllPages;
printCollate = data.printCollate;
printToFile = data.printToFile;
printEnableSelection = data.printEnableSelection;
printEnablePageNumbers = data.printEnablePageNumbers;
printEnableHelp = data.printEnableHelp;
printEnablePrintToFile = data.printEnablePrintToFile;
printSetupDialog = data.printSetupDialog;
printOrientation = data.printOrientation;
}
/*
* wxPageSetupData
*/
wxPageSetupData::wxPageSetupData(void)
{
#if defined(__WIN95__)
m_pageSetupData = NULL;
#endif
m_paperSize = wxPoint(0, 0);
m_minMarginTopLeft = wxPoint(0, 0);
m_minMarginBottomRight = wxPoint(0, 0);
m_marginTopLeft = wxPoint(0, 0);
m_marginBottomRight = wxPoint(0, 0);
m_orientation = wxPORTRAIT;
// Flags
m_defaultMinMargins = FALSE;
m_enableMargins = TRUE;
m_enableOrientation = TRUE;
m_enablePaper = TRUE;
m_enablePrinter = TRUE;
m_enableHelp = FALSE;
m_getDefaultInfo = FALSE;
}
wxPageSetupData::~wxPageSetupData(void)
{
#if defined(__WIN95__)
PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
if ( pd && pd->hDevMode )
GlobalFree(pd->hDevMode);
if ( pd )
delete pd;
#endif
}
void wxPageSetupData::operator=(const wxPageSetupData& data)
{
m_paperSize = data.m_paperSize;
m_minMarginTopLeft = data.m_minMarginTopLeft;
m_minMarginBottomRight = data.m_minMarginBottomRight;
m_marginTopLeft = data.m_marginTopLeft;
m_marginBottomRight = data.m_marginBottomRight;
m_orientation = data.m_orientation;
m_defaultMinMargins = data.m_defaultMinMargins;
m_enableMargins = data.m_enableMargins;
m_enableOrientation = data.m_enableOrientation;
m_enablePaper = data.m_enablePaper;
m_enablePrinter = data.m_enablePrinter;
m_getDefaultInfo = data.m_getDefaultInfo;;
m_enableHelp = data.m_enableHelp;
}
#if defined(__WIN95__)
void wxPageSetupData::ConvertToNative(void)
{
PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
if ( m_pageSetupData == NULL )
{
pd = new PAGESETUPDLG;
pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
m_pageSetupData = (void *)pd;
}
pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
if ( m_defaultMinMargins )
pd->Flags |= PSD_DEFAULTMINMARGINS;
if ( !m_enableMargins )
pd->Flags |= PSD_DISABLEMARGINS;
if ( !m_enableOrientation )
pd->Flags |= PSD_DISABLEORIENTATION;
if ( !m_enablePaper )
pd->Flags |= PSD_DISABLEPAPER;
if ( !m_enablePrinter )
pd->Flags |= PSD_DISABLEPRINTER;
if ( m_getDefaultInfo )
pd->Flags |= PSD_RETURNDEFAULT;
if ( m_enableHelp )
pd->Flags |= PSD_SHOWHELP;
pd->lStructSize = sizeof( PAGESETUPDLG );
pd->hwndOwner=(HANDLE)NULL;
pd->hDevNames=(HWND)NULL;
pd->hInstance=(HINSTANCE)NULL;
pd->ptPaperSize.x = m_paperSize.x;
pd->ptPaperSize.y = m_paperSize.y;
pd->rtMinMargin.left = m_minMarginTopLeft.x;
pd->rtMinMargin.top = m_minMarginTopLeft.y;
pd->rtMinMargin.right = m_minMarginBottomRight.x;
pd->rtMinMargin.bottom = m_minMarginBottomRight.y;
pd->rtMargin.left = m_marginTopLeft.x;
pd->rtMargin.top = m_marginTopLeft.y;
pd->rtMargin.right = m_marginBottomRight.x;
pd->rtMargin.bottom = m_marginBottomRight.y;
pd->lCustData = 0;
pd->lpfnPageSetupHook = NULL;
pd->lpfnPagePaintHook = NULL;
pd->hPageSetupTemplate = NULL;
pd->lpPageSetupTemplateName = NULL;
if ( pd->hDevMode )
{
DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
memset(devMode, 0, sizeof(DEVMODE));
devMode->dmSize = sizeof(DEVMODE);
devMode->dmOrientation = m_orientation;
devMode->dmFields = DM_ORIENTATION;
GlobalUnlock(pd->hDevMode);
}
}
void wxPageSetupData::ConvertFromNative(void)
{
PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
if ( !pd )
return;
pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
m_paperSize.x = pd->ptPaperSize.x ;
m_paperSize.y = pd->ptPaperSize.y ;
m_minMarginTopLeft.x = pd->rtMinMargin.left ;
m_minMarginTopLeft.y = pd->rtMinMargin.top ;
m_minMarginBottomRight.x = pd->rtMinMargin.right ;
m_minMarginBottomRight.y = pd->rtMinMargin.bottom ;
m_marginTopLeft.x = pd->rtMargin.left ;
m_marginTopLeft.y = pd->rtMargin.top ;
m_marginBottomRight.x = pd->rtMargin.right ;
m_marginBottomRight.y = pd->rtMargin.bottom ;
if ( pd->hDevMode )
{
DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
m_orientation = devMode->dmOrientation ;
GlobalUnlock(pd->hDevMode);
}
}
void wxPageSetupData::SetOwnerWindow(wxWindow* win)
{
if ( m_pageSetupData == NULL )
ConvertToNative();
if ( m_pageSetupData != NULL && win != NULL)
{
PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
pd->hwndOwner=(HWND) win->GetHWND();
}
}
#endif

153
src/common/config.cpp Normal file
View File

@@ -0,0 +1,153 @@
///////////////////////////////////////////////////////////////////////////////
// Name: config.cpp
// Purpose: implementation of wxConfig class
// Author: Vadim Zeitlin
// Modified by:
// Created: 07.04.98
// RCS-ID: $Id$
// Copyright: (c) 1997 Karsten Ball<6C>der Ballueder@usa.net
// Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// headers
// ============================================================================
#ifdef __GNUG__
#pragma implementation "app.h"
#endif
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#include <wx/string.h>
#include <wx/intl.h>
#include <wx/file.h>
#include <wx/log.h>
#include <wx/textfile.h>
#include <wx/config.h>
#include <stdlib.h>
#include <ctype.h>
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxConfig
// ----------------------------------------------------------------------------
wxConfig::~wxConfig()
{
}
// ----------------------------------------------------------------------------
// static & global functions
// ----------------------------------------------------------------------------
// understands both Unix and Windows (but only under Windows) environment
// variables expansion: i.e. $var, $(var) and ${var} are always understood
// and in addition under Windows %var% is also.
wxString ExpandEnvVars(const wxString& str)
{
wxString strResult;
// don't change the values the enum elements: they must be equal
// to the matching [closing] delimiter.
enum Bracket
{
Bracket_None,
Bracket_Normal = ')',
Bracket_Curly = '}',
#ifdef __WINDOWS__
Bracket_Windows = '%' // yeah, Windows people are a bit strange ;-)
#endif
};
uint m;
for ( uint n = 0; n < str.Len(); n++ ) {
switch ( str[n] ) {
#ifdef __WINDOWS__
case '%':
#endif //WINDOWS
case '$':
{
Bracket bracket;
#ifdef __WINDOWS__
if ( str[n] == '%' )
bracket = Bracket_Windows;
else
#endif //WINDOWS
if ( n == str.Len() - 1 ) {
bracket = Bracket_None;
}
else {
switch ( str[n + 1] ) {
case '(':
bracket = Bracket_Normal;
n++; // skip the bracket
break;
case '{':
bracket = Bracket_Curly;
n++; // skip the bracket
break;
default:
bracket = Bracket_None;
}
}
m = n + 1;
while ( m < str.Len() && (isalnum(str[m]) || str[m] == '_') )
m++;
wxString strVarName(str.c_str() + n + 1, m - n - 1);
const char *pszValue = getenv(strVarName);
if ( pszValue != NULL ) {
strResult += pszValue;
}
else {
// variable doesn't exist => don't change anything
#ifdef __WINDOWS__
if ( bracket != Bracket_Windows )
#endif
if ( bracket != Bracket_None )
strResult << str[n - 1];
strResult << str[n] << strVarName;
}
// check the closing bracket
if ( bracket != Bracket_None ) {
if ( m == str.Len() || str[m] != (char)bracket ) {
wxLogWarning("missing '%c' at position %d in '%s'.",
(char)bracket, m + 1, str.c_str());
}
else {
// skip closing bracket
if ( pszValue == NULL )
strResult << (char)bracket;
m++;
}
}
n = m - 1; // skip variable name
}
break;
case '\\':
n++;
// fall through
default:
strResult += str[n];
}
}
return strResult;
}

650
src/common/date.cpp Normal file
View File

@@ -0,0 +1,650 @@
/////////////////////////////////////////////////////////////////////////////
// Name: date.cpp
// Purpose: wxDate class
// Author:
// Originally inspired by Steve Marcus (CIS 72007,1233) 6/16/91
// Enhanced by Eric Simon (CIS 70540,1522) 6/29/91
// Further Enhanced by Chris Hill (CIS 72030,2606) 7/11/91
// Still Further Enhanced by Hill & Simon v3.10 8/05/91
// Version 4 by Charles D. Price 6/27/92
// Integrated into wxWindows by Julian Smart 9th July 1995
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "date.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/setup.h"
#if USE_TIMEDATE
#include "wx/date.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if USE_IOSTREAMH
#include <iostream.h>
#else
#include <iostream>
#endif
#include <time.h>
#include <string.h>
#define ABBR_LENGTH 3
static const char *dayname[] = {"Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday"} ;
static const char *mname[] = {"January","February","March","April","May",
"June","July","August","September","October","November","December"};
static int GauDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxDate, wxObject)
#endif
////////////////////////////////////////////////////////////
// Constructors
////////////////////////////////////////////////////////////
wxDate::wxDate()
{
DisplayFormat=wxMDY;
DisplayOptions='\0';
month = day = year = day_of_week = 0;
julian = 0;
}
wxDate::wxDate (const long j) : julian(j)
{
DisplayFormat=wxMDY;
DisplayOptions='\0';
julian_to_mdy ();
}
wxDate::wxDate (const int m, const int d, const int y) : month(m), day(d), year(y)
{
DisplayFormat=wxMDY;
DisplayOptions='\0';
mdy_to_julian ();
}
wxDate::wxDate (const wxString& dat)
{
DisplayFormat=wxMDY;
DisplayOptions='\0';
if (strcmp(dat, "TODAY") == 0 || strcmp(dat, "today") == 0)
{
// Sets the current date
Set();
}
else
{
char buf[100];
strcpy(buf, (char *) (const char *)dat);
char *token = strtok(buf,"/-");
month = atoi(token);
day = atoi(strtok(NULL,"/-"));
year = atoi(strtok(NULL," "));
}
mdy_to_julian ();
}
wxDate::wxDate (const wxDate &dt)
{
DisplayFormat=dt.DisplayFormat;
DisplayOptions=dt.DisplayOptions;
month = dt.month;
day = dt.day;
year = dt.year;
mdy_to_julian ();
}
void wxDate::operator = (const wxDate &dt)
{
DisplayFormat=dt.DisplayFormat;
DisplayOptions=dt.DisplayOptions;
month = dt.month;
day = dt.day;
year = dt.year;
mdy_to_julian ();
}
void wxDate::operator = (const wxString& dat)
{
DisplayFormat=wxMDY;
DisplayOptions='\0';
if (strcmp(dat, "TODAY") == 0 || strcmp(dat, "today") == 0)
{
// Sets the current date
Set();
}
else
{
char buf[100];
strcpy(buf, (char *)(const char *)dat);
char *token = strtok(buf,"/-");
month = atoi(token);
day = atoi(strtok(NULL,"/-"));
year = atoi(strtok(NULL," "));
}
mdy_to_julian ();
}
//////////////////////////////////////////////////////////////
// Conversion operations
//////////////////////////////////////////////////////////////
wxDate::operator wxString( void )
{
return FormatDate();
}
//////////////////////////////////////////////////////////////
// Date Arithmetic
//////////////////////////////////////////////////////////////
wxDate wxDate::operator + (const long i)
{
wxDate dp(julian + i);
return dp;
}
wxDate wxDate::operator + (const int i)
{
wxDate dp(julian + (long)i);
return dp;
}
wxDate wxDate::operator - (const long i)
{
wxDate dp(julian - i);
return dp;
}
wxDate wxDate::operator - (const int i)
{
wxDate dp(julian - (long)i);
return dp;
}
long wxDate::operator - (const wxDate &dt)
{
return ( julian - dt.julian );
}
wxDate &wxDate::operator += (const long i)
{
julian += i;
julian_to_mdy();
return *this;
}
wxDate &wxDate::operator -= (const long i)
{
julian -= i;
julian_to_mdy();
return *this;
}
wxDate &wxDate::operator ++()
{
julian++;
julian_to_mdy();
return *this;
}
wxDate &wxDate::operator ++(int)
{
julian++;
julian_to_mdy();
return *this;
}
wxDate &wxDate::operator --()
{
julian--;
julian_to_mdy();
return *this;
}
wxDate &wxDate::operator --(int)
{
julian--;
julian_to_mdy();
return *this;
}
//////////////////////////////////////////////////////////////
// Date comparison
//////////////////////////////////////////////////////////////
bool operator < (const wxDate &dt1, const wxDate &dt2)
{
return ( dt1.julian < dt2.julian );
}
bool operator <= (const wxDate &dt1, const wxDate &dt2)
{
return ( (dt1.julian == dt2.julian) || (dt1.julian < dt2.julian) );
}
bool operator > (const wxDate &dt1, const wxDate &dt2)
{
return ( dt1.julian > dt2.julian );
}
bool operator >= (const wxDate &dt1, const wxDate &dt2)
{
return ( (dt1.julian == dt2.julian) || (dt1.julian > dt2.julian) );
}
bool operator == (const wxDate &dt1, const wxDate &dt2)
{
return ( dt1.julian == dt2.julian );
}
bool operator != (const wxDate &dt1, const wxDate &dt2)
{
return ( dt1.julian != dt2.julian );
}
////////////////////////////////////////////////////////////////
// Ostream operations
////////////////////////////////////////////////////////////////
ostream &operator << (ostream &os, const wxDate &dt)
{
return os << (const char *) dt.FormatDate();
}
//////////////////////////////////////////////////////////////
// Conversion routines
//////////////////////////////////////////////////////////////
void wxDate::julian_to_wday (void)
{
day_of_week = (int) ((julian + 2) % 7 + 1);
}
void wxDate::julian_to_mdy ()
{
long a,b,c,d,e,z,alpha;
z = julian+1;
// dealing with Gregorian calendar reform
if (z < 2299161L)
a = z;
else {
alpha = (long) ((z-1867216.25) / 36524.25);
a = z + 1 + alpha - alpha/4;
}
b = ( a > 1721423 ? a + 1524 : a + 1158 );
c = (long) ((b - 122.1) / 365.25);
d = (long) (365.25 * c);
e = (long) ((b - d) / 30.6001);
day = (int)(b - d - (long)(30.6001 * e));
month = (int)((e < 13.5) ? e - 1 : e - 13);
year = (int)((month > 2.5 ) ? (c - 4716) : c - 4715);
julian_to_wday ();
}
void wxDate::mdy_to_julian (void)
{
int a,b=0;
int work_month=month, work_day=day, work_year=year;
// correct for negative year
if (work_year < 0)
work_year++;
if (work_month <= 2)
{ work_year--; work_month +=12; }
// deal with Gregorian calendar
if (work_year*10000. + work_month*100. + work_day >= 15821015.)
{
a = (int)(work_year/100.);
b = 2 - a + a/4;
}
julian = (long) (365.25*work_year) +
(long) (30.6001 * (work_month+1)) + work_day + 1720994L + b;
julian_to_wday ();
}
////////////////////////////////////////////////////////////////
// Format routine
////////////////////////////////////////////////////////////////
wxString wxDate::FormatDate (const int type) const
{
int actualType = type;
if (actualType == -1)
actualType = DisplayFormat;
char buf[40];
memset( buf, '\0', sizeof(buf) );
switch ( actualType )
{
case wxDAY:
if ( (day_of_week < 1) || (day_of_week > 7) )
strcpy(buf,"invalid day");
else
strncpy( buf, dayname[day_of_week-1],
(DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
return wxString(buf);
case wxMONTH:
if ( (month < 1) || (month > 12) )
strcpy(buf,"invalid month");
else
strncpy( buf, mname[month-1],
(DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
return wxString(buf);
case wxFULL:
if ( (month < 1) || (month > 12) || (day_of_week < 0) ||
(day_of_week > 7) )
{
strcpy(buf,"invalid date");
return wxString(buf);
}
strncpy( buf, dayname[day_of_week-1],
(DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
strcat( buf, ", ");
strncat( buf, mname[month-1],
(DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
strcat( buf, " ");
sprintf( buf+strlen(buf), "%d, %d", day, abs(year) );
if (year < 0)
strcat(buf," B.C.");
return wxString(buf);
case wxEUROPEAN:
if ( (month < 1) || (month > 12) || (day_of_week < 0) ||
(day_of_week > 7) )
{
strcpy(buf,"invalid date");
return wxString(buf);
}
sprintf(buf,"%d ", day);
strncat(buf, mname[month-1],
(DisplayOptions & wxDATE_ABBR) ? ABBR_LENGTH : 9);
sprintf( buf+strlen(buf), " %d", abs(year) );
if (year < 0)
strcat(buf," B.C.");
return wxString(buf);
case wxMDY:
default:
if (day==0 || month==0 || year==0)
strcpy(buf,"invalid date");
else
sprintf( buf+strlen(buf), "%1d/%1d/%02d", month, day,
(DisplayOptions & wxNO_CENTURY) && (abs(year) > 1899)
? (abs(year) - (abs(year) / 100 * 100))
: (abs(year)) );
return wxString(buf);
}
return wxString("");
}
void wxDate::SetFormat( const int format )
{
DisplayFormat = format;
}
int wxDate::SetOption( const int option, const bool action )
{
switch ( option )
{
case wxNO_CENTURY:
if ( action )
DisplayOptions |= wxNO_CENTURY;
else
{
DisplayOptions &= (~wxNO_CENTURY);
}
return 1;
case wxDATE_ABBR:
if ( action )
DisplayOptions |= wxDATE_ABBR;
else
{
DisplayOptions &= (~wxDATE_ABBR);
}
return 1;
default:
return 0;
}
return 0;
}
///////////////////////////////////////////////////////////////
// Miscellaneous Routines
///////////////////////////////////////////////////////////////
long wxDate::GetJulianDate( void ) const
{
return julian;
}
int wxDate::GetDayOfYear( void ) const
{
wxDate temp( 1, 1, year );
return (int) (julian - temp.julian + 1);
}
bool wxDate::IsLeapYear( void ) const
{
return ( (year >= 1582) ?
(year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ):
(year % 4 == 0) );
}
// Version 4.0 Extension to Public Interface - CDP
wxDate& wxDate::Set()
{
//#ifdef __WINDOWS__
#if 0
struct _dosdate_t sDate;
_dos_getdate(&sDate);
month = sDate.month;
day = sDate.day;
year = sDate.year;
mdy_to_julian();
#else
time_t now = time(NULL);
struct tm *localTime = localtime(&now);
month = localTime->tm_mon + 1;
day = localTime->tm_mday;
year = localTime->tm_year + 1900;
mdy_to_julian ();
#endif
return *this;
}
wxDate& wxDate::Set(
int nMonth,
int nDay,
int nYear)
{
month = nMonth;
year = nYear < 0 ? 9999 : nYear;
year = nYear > 9999 ? 0 : nYear;
day = nDay < GetDaysInMonth() ? nDay : GetDaysInMonth();
mdy_to_julian();
return *this;
}
wxDate &
wxDate::Set(long j)
{
julian = j;
julian_to_mdy();
return *this;
}
int wxDate::GetDaysInMonth()
{
return GauDays[month-1] + (month==2 && IsLeapYear());
}
int wxDate::GetFirstDayOfMonth() const
{
return wxDate(month, 1, year).GetDayOfWeek();
}
int wxDate::GetDay() const
{
return day;
}
int wxDate::GetDayOfWeek() const
{
return day_of_week;
}
int wxDate::GetYear() const
{
return year;
}
int wxDate::GetMonth() const
{
return month;
}
wxDate& wxDate::AddWeeks(int nCount)
{
Set(julian + (long)nCount*7);
return *this;
}
wxDate& wxDate::AddMonths(int nCount)
{
month += nCount;
if (month < 1) {
month = 12;
year--;
}
if (month > 12) {
month = 1;
year++;
}
mdy_to_julian();
return *this;
}
wxDate& wxDate::AddYears(int nCount)
{
year += nCount;
mdy_to_julian();
return *this;
}
int wxDate::GetWeekOfMonth()
{
// Abs day includes the days from previous month that fills up
// the begin. of the week.
int nAbsDay = day + GetFirstDayOfMonth()-1;
return (nAbsDay-GetDayOfWeek())/7 + 1;
}
int wxDate::GetWeekOfYear()
{
wxDate doTemp(1, 1, year);
return (int)(((julian - doTemp.julian+1)/7) + 1);
}
wxDate wxDate::GetMonthStart()
{
return(wxDate(month, 1, year));
}
wxDate wxDate::GetMonthEnd()
{
return(wxDate(month+1, 1, year)-1);
}
wxDate wxDate::GetYearStart()
{
return(wxDate(1, 1, year));
}
wxDate wxDate::GetYearEnd()
{
return(wxDate(1, 1, year+1)-1);
}
wxString wxDate::GetMonthName()
{
return(FormatDate(wxMONTH));
}
wxString wxDate::GetDayOfWeekName()
{
return(FormatDate(wxDAY));
}
bool wxDate::IsBetween(const wxDate& first, const wxDate& second) const
{
return (julian >= first.julian && julian <= second.julian);
}
// This function is from NIHCL
wxDate wxDate::Previous(const int dayOfWeek) const
{
int this_day_Of_Week, desired_day_Of_Week;
long j;
// Set the desired and current day of week to start at 0 (Monday)
// and end at 6 (Sunday).
desired_day_Of_Week = dayOfWeek - 1; // These functions return a value
this_day_Of_Week = GetDayOfWeek() - 1; // from 1-7. Subtract 1 for 0-6.
j = julian;
// Have to determine how many days difference from current day back to
// desired, if any. Special calculation under the 'if' statement to
// effect the wraparound counting from Monday (0) back to Sunday (6).
if (desired_day_Of_Week > this_day_Of_Week)
this_day_Of_Week += 7 - desired_day_Of_Week;
else
this_day_Of_Week -= desired_day_Of_Week;
j -= this_day_Of_Week; // Adjust j to set it at the desired day of week.
return wxDate(j);
}
#endif

1898
src/common/docview.cpp Normal file

File diff suppressed because it is too large Load Diff

216
src/common/dynarray.cpp Normal file
View File

@@ -0,0 +1,216 @@
///////////////////////////////////////////////////////////////////////////////
// Name: dynarray.cpp
// Purpose: implementation of wxBaseArray class
// Author: Vadim Zeitlin
// Modified by:
// Created: 12.09.97
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// headers
// ============================================================================
#ifdef __GNUG__
#pragma implementation "dynarray.h"
#endif
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/dynarray.h"
#include <stdlib.h>
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
// ============================================================================
// constants
// ============================================================================
// size increment = max(50% of current size, ARRAY_MAXSIZE_INCREMENT)
#define ARRAY_MAXSIZE_INCREMENT 4096
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxBaseArray - dynamice array of 'long's
// ----------------------------------------------------------------------------
// ctor
wxBaseArray::wxBaseArray()
{
m_uiSize =
m_uiCount = 0;
m_pItems = NULL;
}
// copy ctor
wxBaseArray::wxBaseArray(const wxBaseArray& src)
{
m_uiSize = src.m_uiSize;
m_uiCount = src.m_uiCount;
if ( m_uiSize != 0 )
m_pItems = new long[m_uiSize];
else
m_pItems = NULL;
if ( m_uiCount != 0 )
memcpy(m_pItems, src.m_pItems, m_uiCount*sizeof(long));
}
// copy operator
wxBaseArray& wxBaseArray::operator=(const wxBaseArray& src)
{
DELETEA(m_pItems);
m_uiSize = src.m_uiSize;
m_uiCount = src.m_uiCount;
if ( m_uiSize != 0 )
m_pItems = new long[m_uiSize];
else
m_pItems = NULL;
if ( m_uiCount != 0 )
memcpy(m_pItems, src.m_pItems, m_uiCount*sizeof(long));
return *this;
}
// grow the array
void wxBaseArray::Grow()
{
// only do it if no more place
if( m_uiCount == m_uiSize ) {
if( m_uiSize == 0 ) {
// was empty, alloc some memory
m_uiSize = WX_ARRAY_DEFAULT_INITIAL_SIZE;
m_pItems = new long[m_uiSize];
}
else
{
// add 50% but not too much
uint uiIncrement = m_uiSize >> 1;
if ( uiIncrement > ARRAY_MAXSIZE_INCREMENT )
uiIncrement = ARRAY_MAXSIZE_INCREMENT;
m_uiSize += uiIncrement;
long *pNew = new long[m_uiSize];
// copy data to new location
memcpy(pNew, m_pItems, m_uiCount*sizeof(long));
delete [] m_pItems;
m_pItems = pNew;
}
}
}
// dtor
wxBaseArray::~wxBaseArray()
{
DELETEA(m_pItems);
}
// clears the list
void wxBaseArray::Clear()
{
m_uiSize =
m_uiCount = 0;
DELETEA(m_pItems);
m_pItems = NULL;
}
// pre-allocates memory (frees the previous data!)
void wxBaseArray::Alloc(uint uiSize)
{
wxASSERT( uiSize > 0 );
// only if old buffer was not big enough
if ( uiSize > m_uiSize ) {
DELETEA(m_pItems);
m_pItems = new long[uiSize];
m_uiSize = uiSize;
}
m_uiCount = 0;
}
// searches the array for an item (forward or backwards)
int wxBaseArray::Index(long lItem, Bool bFromEnd) const
{
if ( bFromEnd ) {
if ( m_uiCount > 0 ) {
uint ui = m_uiCount;
do {
if ( m_pItems[--ui] == lItem )
return ui;
}
while ( ui != 0 );
}
}
else {
for( uint ui = 0; ui < m_uiCount; ui++ ) {
if( m_pItems[ui] == lItem )
return ui;
}
}
return NOT_FOUND;
}
// add item at the end
void wxBaseArray::Add(long lItem)
{
Grow();
m_pItems[m_uiCount++] = lItem;
}
// add item at the given position
void wxBaseArray::Insert(long lItem, uint uiIndex)
{
wxCHECK( uiIndex <= m_uiCount );
Grow();
memmove(&m_pItems[uiIndex + 1], &m_pItems[uiIndex],
(m_uiCount - uiIndex)*sizeof(long));
m_pItems[uiIndex] = lItem;
m_uiCount++;
}
// removes item from array (by index)
void wxBaseArray::Remove(uint uiIndex)
{
wxCHECK( uiIndex <= m_uiCount );
memmove(&m_pItems[uiIndex], &m_pItems[uiIndex + 1],
(m_uiCount - uiIndex - 1)*sizeof(long));
m_uiCount--;
}
// removes item from array (by value)
void wxBaseArray::Remove(long lItem)
{
int iIndex = Index(lItem);
wxCHECK( iIndex != NOT_FOUND );
Remove((uint)iIndex);
}
// sort array elements using passed comparaison function
void wxBaseArray::Sort(CMPFUNC fCmp)
{
qsort(m_pItems, m_uiCount, sizeof(long), fCmp);
}

442
src/common/event.cpp Normal file
View File

@@ -0,0 +1,442 @@
/////////////////////////////////////////////////////////////////////////////
// Name: event.cpp
// Purpose: Event classes
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "event.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include "wx/control.h"
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/dc.h"
#endif
#include "wx/event.h"
#include "wx/validate.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxEvent)
const wxEventTable *wxEvtHandler::GetEventTable() const { return &wxEvtHandler::sm_eventTable; }
const wxEventTable wxEvtHandler::sm_eventTable =
{ NULL, &wxEvtHandler::sm_eventTableEntries[0] };
const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { { 0, 0, 0, NULL } };
#endif
/*
* General wxWindows events, covering
* all interesting things that might happen (button clicking, resizing,
* setting text in widgets, etc.).
*
* For each completely new event type, derive a new event class.
*
*/
wxEvent::wxEvent(int theId)
{
m_eventType = 0;
m_eventObject = NULL;
m_eventHandle = NULL;
m_timeStamp = 0;
m_id = theId;
m_skipped = FALSE;
}
/*
* Command events
*
*/
wxCommandEvent::wxCommandEvent(WXTYPE commandType, int theId)
{
m_eventType = commandType;
m_clientData = NULL;
m_extraLong = 0;
m_commandInt = 0;
m_id = theId;
m_commandString = NULL;
}
/*
* Scroll events
*/
wxScrollEvent::wxScrollEvent(WXTYPE commandType, int id, int pos, int orient):
wxCommandEvent(commandType, id)
{
m_extraLong = orient;
m_commandInt = pos;
}
/*
* Mouse events
*
*/
wxMouseEvent::wxMouseEvent(WXTYPE commandType)
{
m_eventType = commandType;
m_metaDown = FALSE;
m_altDown = FALSE;
m_controlDown = FALSE;
m_shiftDown = FALSE;
}
// True if was a button dclick event (1 = left, 2 = middle, 3 = right)
// or any button dclick event (but = -1)
bool wxMouseEvent::ButtonDClick(int but) const
{
switch (but) {
case -1:
return (LeftDClick() || MiddleDClick() || RightDClick());
case 1:
return LeftDClick();
case 2:
return MiddleDClick();
case 3:
return RightDClick();
default:
return FALSE;
}
// NOTREACHED
}
// True if was a button down event (1 = left, 2 = middle, 3 = right)
// or any button down event (but = -1)
bool wxMouseEvent::ButtonDown(int but) const
{
switch (but) {
case -1:
return (LeftDown() || MiddleDown() || RightDown());
case 1:
return LeftDown();
case 2:
return MiddleDown();
case 3:
return RightDown();
default:
return FALSE;
}
// NOTREACHED
}
// True if was a button up event (1 = left, 2 = middle, 3 = right)
// or any button up event (but = -1)
bool wxMouseEvent::ButtonUp(int but) const
{
switch (but) {
case -1:
return (LeftUp() || MiddleUp() || RightUp());
case 1:
return LeftUp();
case 2:
return MiddleUp();
case 3:
return RightUp();
default:
return FALSE;
}
// NOTREACHED
}
// True if the given button is currently changing state
bool wxMouseEvent::Button(int but) const
{
switch (but) {
case -1:
return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1)) ;
case 1:
return (LeftDown() || LeftUp() || LeftDClick());
case 2:
return (MiddleDown() || MiddleUp() || MiddleDClick());
case 3:
return (RightDown() || RightUp() || RightDClick());
default:
return FALSE;
}
// NOTREACHED
}
bool wxMouseEvent::ButtonIsDown(int but) const
{
switch (but) {
case -1:
return (LeftIsDown() || MiddleIsDown() || RightIsDown());
case 1:
return LeftIsDown();
case 2:
return MiddleIsDown();
case 3:
return RightIsDown();
default:
return FALSE;
}
// NOTREACHED
}
// Find the logical position of the event given the DC
wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
{
wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
return pt;
}
/*
* Keyboard events
*
*/
wxKeyEvent::wxKeyEvent(WXTYPE type)
{
m_eventType = type;
m_shiftDown = FALSE;
m_controlDown = FALSE;
m_metaDown = FALSE;
m_altDown = FALSE;
m_keyCode = 0;
}
/*
* Event handler
*/
wxEvtHandler::wxEvtHandler(void)
{
m_clientData = NULL;
m_nextHandler = NULL;
m_previousHandler = NULL;
m_enabled = TRUE;
}
wxEvtHandler::~wxEvtHandler(void)
{
// Takes itself out of the list of handlers
if (m_previousHandler)
m_previousHandler->m_nextHandler = m_nextHandler;
if (m_nextHandler)
m_nextHandler->m_previousHandler = m_previousHandler;
}
/*
* Event table stuff
*/
bool wxEvtHandler::ProcessEvent(wxEvent& event)
{
// An event handler can be enabled or disabled
if ( GetEvtHandlerEnabled() )
{
const wxEventTable *table = GetEventTable();
// Try the associated validator first, if this is a window.
// Problem: if the event handler of the window has been replaced,
// this wxEvtHandler may no longer be a window.
// Therefore validators won't be processed if the handler
// has been replaced with SetEventHandler.
// THIS CAN BE CURED if PushEventHandler is used instead of
// SetEventHandler, and then processing will be passed down the
// chain of event handlers.
if (IsKindOf(CLASSINFO(wxWindow)))
{
wxWindow *win = (wxWindow *)this;
// Can only use the validator of the window which
// is receiving the event
if ( (win == event.GetEventObject()) &&
win->GetValidator() &&
win->GetValidator()->ProcessEvent(event))
return TRUE;
}
// Search upwards through the inheritance hierarchy
while (table)
{
if (SearchEventTable((wxEventTable&)*table, event))
return TRUE;
table = table->baseTable;
}
}
// Try going down the event handler chain
if ( GetNextHandler() )
{
if ( GetNextHandler()->ProcessEvent(event) )
return TRUE;
}
// Carry on up the parent-child hierarchy,
// but only if event is a command event: it wouldn't
// make sense for a parent to receive a child's size event, for example
if (IsKindOf(CLASSINFO(wxWindow)) && event.IsKindOf(CLASSINFO(wxCommandEvent)))
{
wxWindow *win = (wxWindow *)this;
wxWindow *parent = win->GetParent();
if (parent && !parent->IsBeingDeleted())
return win->GetParent()->GetEventHandler()->ProcessEvent(event);
}
// Last try - application object
if (wxTheApp && this != wxTheApp && wxTheApp->ProcessEvent(event))
return TRUE;
else
return FALSE;
}
bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
{
int i = 0;
int commandId = event.GetId();
while (table.entries[i].m_fn != NULL)
{
if ((event.GetEventType() == table.entries[i].m_eventType) &&
(table.entries[i].m_id == -1 || // Match, if event spec says any id will do (id == -1)
(table.entries[i].m_lastId == -1 && commandId == table.entries[i].m_id) ||
(table.entries[i].m_lastId != -1 &&
(commandId >= table.entries[i].m_id && commandId <= table.entries[i].m_lastId))))
{
event.Skip(FALSE);
(this->*((wxEventFunction) (table.entries[i].m_fn)))(event);
if ( event.GetSkipped() )
return FALSE;
else
return TRUE;
}
i ++;
}
return FALSE;
}
#if WXWIN_COMPATIBILITY
void wxEvtHandler::OldOnMenuCommand(int cmd)
{
if (GetNextHandler()) GetNextHandler()->OldOnMenuCommand(cmd);
}
void wxEvtHandler::OldOnMenuSelect(int cmd)
{
if (GetNextHandler()) GetNextHandler()->OldOnMenuSelect(cmd);
}
void wxEvtHandler::OldOnInitMenuPopup(int pos)
{
if (GetNextHandler()) GetNextHandler()->OldOnInitMenuPopup(pos);
}
void wxEvtHandler::OldOnScroll(wxCommandEvent& event)
{
if (GetNextHandler()) GetNextHandler()->OldOnScroll(event);
}
void wxEvtHandler::OldOnPaint(void)
{
if (GetNextHandler()) GetNextHandler()->OldOnPaint();
}
void wxEvtHandler::OldOnSize(int width, int height)
{
if (GetNextHandler()) GetNextHandler()->OldOnSize(width, height);
}
void wxEvtHandler::OldOnMove(int x, int y)
{
if (GetNextHandler()) GetNextHandler()->OldOnMove(x, y);
}
void wxEvtHandler::OldOnMouseEvent(wxMouseEvent& event)
{
if (GetNextHandler()) GetNextHandler()->OldOnMouseEvent(event);
}
void wxEvtHandler::OldOnChar(wxKeyEvent& event)
{
if (GetNextHandler()) GetNextHandler()->OldOnChar(event);
}
// Under Windows, we can intercept character input per dialog or frame
bool wxEvtHandler::OldOnCharHook(wxKeyEvent& event)
{
if (GetNextHandler()) return GetNextHandler()->OldOnCharHook(event);
else return FALSE;
}
void wxEvtHandler::OldOnActivate(bool active)
{
if (GetNextHandler()) GetNextHandler()->OldOnActivate(active);
}
void wxEvtHandler::OldOnSetFocus(void)
{
if (GetNextHandler()) GetNextHandler()->OldOnSetFocus();
}
void wxEvtHandler::OldOnKillFocus(void)
{
if (GetNextHandler()) GetNextHandler()->OldOnKillFocus();
}
bool wxEvtHandler::OldOnSysColourChange(void)
{
if (GetNextHandler()) return GetNextHandler()->OldOnSysColourChange();
return FALSE;
}
void wxEvtHandler::OldOnDropFiles(int n, char *files[], int x, int y)
{
if (GetNextHandler()) GetNextHandler()->OldOnDropFiles(n, files, x, y);
}
#endif
bool wxEvtHandler::OnClose(void)
{
if (GetNextHandler()) return GetNextHandler()->OnClose();
else return FALSE;
}

399
src/common/file.cpp Normal file
View File

@@ -0,0 +1,399 @@
/////////////////////////////////////////////////////////////////////////////
// Name: file.cpp
// Purpose: wxFile - encapsulates low-level "file descriptor"
// wxTempFile
// Author: Vadim Zeitlin
// Modified by:
// Created: 29/01/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "file.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/defs.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// standard
#if defined(__WINDOWS__) && !defined(__GNUWIN32__)
#include <io.h>
#elif (defined(__UNIX__) || defined(__GNUWIN32__))
#include <unistd.h>
#else
#error "Please specify the header with file functions declarations."
#endif //Win/UNIX
#include <stdio.h> // SEEK_xxx constants
#include <fcntl.h> // O_RDONLY &c
#include <sys/types.h> // needed for stat
#include <sys/stat.h> // stat
// Microsoft compiler loves underscores, feed them to it
#ifdef _MSC_VER
// functions
#define open _open
#define close _close
#define read _read
#define write _write
#define lseek _lseek
#define fsync _commit
#define access _access
#define eof _eof
// types
#define stat _stat
// constants
#define O_RDONLY _O_RDONLY
#define O_WRONLY _O_WRONLY
#define O_RDWR _O_RDWR
#define O_EXCL _O_EXCL
#define O_CREAT _O_CREAT
#define O_BINARY _O_BINARY
#define S_IFDIR _S_IFDIR
#define S_IFREG _S_IFREG
#define S_IREAD _S_IREAD
#define S_IWRITE _S_IWRITE
#else
#define tell(fd) lseek(fd, 0, SEEK_CUR)
#endif //_MSC_VER
// there is no distinction between text and binary files under Unix
#ifdef __UNIX__
#define O_BINARY (0)
#endif //__UNIX__
// wxWindows
#include <wx/string.h>
#include <wx/intl.h>
#include <wx/file.h>
#include <wx/log.h>
// ============================================================================
// implementation of wxFile
// ============================================================================
// ----------------------------------------------------------------------------
// static functions
// ----------------------------------------------------------------------------
bool wxFile::Exists(const char *sz)
{
struct stat st;
return !access(sz, 0) && !stat(sz, &st) && (st.st_mode & S_IFREG);
}
// ----------------------------------------------------------------------------
// opening/closing
// ----------------------------------------------------------------------------
// ctors
wxFile::wxFile(const char *szFileName, OpenMode mode)
{
m_fd = fd_invalid;
Open(szFileName, mode);
}
// dtor
wxFile::~wxFile()
{
Close();
}
// create the file, fail if it already exists and bOverwrite
bool wxFile::Create(const char *szFileName, bool bOverwrite)
{
// if bOverwrite we create a new file or truncate the existing one,
// otherwise we only create the new file and fail if it already exists
int fd = bOverwrite ? creat(szFileName, 0)
: open(szFileName, O_CREAT | O_EXCL);
if ( fd == -1 ) {
wxLogSysError("can't create file '%s'", szFileName);
return FALSE;
}
else {
Attach(fd);
return TRUE;
}
}
// open the file
bool wxFile::Open(const char *szFileName, OpenMode mode)
{
int flags = O_BINARY;
switch ( mode ) {
case read:
flags |= O_RDONLY;
break;
case write:
flags |= O_WRONLY | O_CREAT;
break;
case read_write:
flags |= O_RDWR;
break;
}
int fd = open(szFileName, flags, S_IREAD | S_IWRITE);
if ( fd == -1 ) {
wxLogSysError("can't open file '%s'", szFileName);
return FALSE;
}
else {
Attach(fd);
return TRUE;
}
}
// close
void wxFile::Close()
{
if ( IsOpened() ) {
if ( close(m_fd) == -1 )
wxLogSysError("can't close file descriptor %d", m_fd);
m_fd = fd_invalid;
}
}
// ----------------------------------------------------------------------------
// read/write
// ----------------------------------------------------------------------------
// read
off_t wxFile::Read(void *pBuf, off_t nCount)
{
wxCHECK_RET( (pBuf != NULL) && IsOpened(), 0 );
int iRc = ::read(m_fd, pBuf, nCount);
if ( iRc == -1 ) {
wxLogSysError("can't read from file descriptor %d", m_fd);
return ofsInvalid;
}
else
return (uint)iRc;
}
// write
bool wxFile::Write(const void *pBuf, uint nCount)
{
wxCHECK_RET( (pBuf != NULL) && IsOpened(), 0 );
int iRc = ::write(m_fd, pBuf, nCount);
if ( iRc == -1 ) {
wxLogSysError("can't write to file descriptor %d", m_fd);
return FALSE;
}
else
return TRUE;
}
// flush
bool wxFile::Flush()
{
if ( IsOpened() ) {
// ## fsync() is not ANSI (BSDish)
// if ( fsync(m_fd) == -1 ) { // TODO
if (TRUE) {
wxLogSysError("can't flush file descriptor %d", m_fd);
return FALSE;
}
}
return TRUE;
}
// ----------------------------------------------------------------------------
// seek
// ----------------------------------------------------------------------------
// seek
off_t wxFile::Seek(off_t ofs, SeekMode mode)
{
wxASSERT( IsOpened() );
int flag = -1;
switch ( mode ) {
case FromStart:
flag = SEEK_SET;
break;
case FromCurrent:
flag = SEEK_CUR;
break;
case FromEnd:
flag = SEEK_END;
break;
default:
wxFAIL_MSG("unknown seek origin");
}
int iRc = lseek(m_fd, ofs, flag);
if ( iRc == -1 ) {
wxLogSysError("can't seek on file descriptor %d", m_fd);
return ofsInvalid;
}
else
return (off_t)iRc;
}
// get current off_t
off_t wxFile::Tell() const
{
wxASSERT( IsOpened() );
int iRc = tell(m_fd);
if ( iRc == -1 ) {
wxLogSysError("can't get seek position on file descriptor %d", m_fd);
return ofsInvalid;
}
else
return (off_t)iRc;
}
// get current file length
off_t wxFile::Length() const
{
wxASSERT( IsOpened() );
#ifdef _MSC_VER
int iRc = _filelength(m_fd);
#else
int iRc = tell(m_fd);
if ( iRc != -1 ) {
// # have to use const_cast :-(
int iLen = ((wxFile *)this)->SeekEnd();
if ( iLen != -1 ) {
// restore old position
if ( ((wxFile *)this)->Seek(iRc) == -1 ) {
// error
iLen = -1;
}
}
iRc = iLen;
}
#endif //_MSC_VER
if ( iRc == -1 ) {
wxLogSysError("can't find length of file on file descriptor %d", m_fd);
return ofsInvalid;
}
else
return (off_t)iRc;
}
// is end of file reached?
bool wxFile::Eof() const
{
wxASSERT( IsOpened() );
// TODO: no eof in GnuWin32
#ifdef __LINUX__
int iRc = Tell() == Length();
#else
#if defined(__GNUWIN32__)
int iRc = -1;
#else
int iRc = eof(m_fd);
#endif
#endif
switch ( iRc ) {
case 1:
break;
case 0:
return FALSE;
case -1:
wxLogSysError("can't determine if the end of file is reached on "
"descriptor %d", m_fd);
break;
default:
wxFAIL_MSG("invalid eof() return value.");
}
return TRUE;
}
// ============================================================================
// implementation of wxTempFile
// ============================================================================
// ----------------------------------------------------------------------------
// construction
// ----------------------------------------------------------------------------
wxTempFile::wxTempFile(const wxString& strName)
{
Open(strName);
}
bool wxTempFile::Open(const wxString& strName)
{
m_strName = strName;
m_strTemp = tmpnam(NULL);
return m_file.Open(m_strTemp, wxFile::write);
}
// ----------------------------------------------------------------------------
// destruction
// ----------------------------------------------------------------------------
wxTempFile::~wxTempFile()
{
if ( IsOpened() )
Discard();
}
bool wxTempFile::Commit()
{
m_file.Close();
if ( wxFile::Exists(m_strName) && remove(m_strName) != 0 ) {
wxLogSysError("can't remove file '%s'", m_strName.c_str());
return FALSE;
}
if ( rename(m_strTemp, m_strName) != 0 ) {
wxLogSysError("can't commit changes to file '%s'", m_strName.c_str());
return FALSE;
}
return TRUE;
}
void wxTempFile::Discard()
{
m_file.Close();
if ( remove(m_strTemp) != 0 )
wxLogSysError("can't remove temporary file '%s'", m_strTemp.c_str());
}

1248
src/common/fileconf.cpp Normal file

File diff suppressed because it is too large Load Diff

1314
src/common/filefn.cpp Normal file

File diff suppressed because it is too large Load Diff

603
src/common/gdicmn.cpp Normal file
View File

@@ -0,0 +1,603 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gdicmn.cpp
// Purpose: Common GDI classes
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "gdicmn.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/gdicmn.h"
#include "wx/brush.h"
#include "wx/pen.h"
#include "wx/bitmap.h"
#include "wx/icon.h"
#include "wx/cursor.h"
#include "wx/font.h"
#include "wx/palette.h"
#include <string.h>
#ifdef __WINDOWS__
#include <windows.h>
#endif
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxRect, wxObject)
IMPLEMENT_CLASS(wxColourDatabase, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxPoint, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxRealPoint, wxObject)
#endif
wxRect::wxRect(void)
{
x = 0; y = 0; width = 0; height = 0;
}
wxRect::wxRect(const long xx, const long yy, const long w, const long h)
{
x = xx; y = yy; width = w; height = h;
}
wxRect::wxRect(const wxPoint& topLeft, const wxPoint& bottomRight)
{
x = topLeft.x;
y = topLeft.y;
width = bottomRight.x - topLeft.x;
height = bottomRight.y - topLeft.y;
if (width < 0)
{
width = -width;
x -= width;
}
if (height < 0)
{
height = -height;
x -= height;
}
}
wxRect::wxRect(const wxPoint& point, const wxSize& size)
{
x = point.x; y = point.y;
width = size.x; height = size.y;
}
wxRect::wxRect(const wxRect& rect)
{
x = rect.x;
y = rect.y;
width = rect.width;
height = rect.height;
}
wxRect& wxRect::operator = (const wxRect& rect)
{
x = rect.x; y = rect.y; width = rect.width; height = rect.height;
return *this;
}
bool wxRect::operator == (const wxRect& rect)
{
return ((x == rect.x) &&
(y == rect.y) &&
(width == rect.width) &&
(height == rect.height));
}
bool wxRect::operator != (const wxRect& rect)
{
return ((x != rect.x) ||
(y != rect.y) ||
(width != rect.width) ||
(height != rect.height));
}
wxColourDatabase::wxColourDatabase (int type):
wxList (type)
{
}
wxColourDatabase::~wxColourDatabase (void)
{
// Cleanup Colour allocated in Initialize()
wxNode *node = First ();
while (node)
{
wxColour *col = (wxColour *) node->Data ();
wxNode *next = node->Next ();
delete col;
node = next;
}
}
// Colour database stuff
void wxColourDatabase::Initialize (void)
{
// Don't initialize for X: colours are found
// in FindColour below.
// Added: Not all
struct cdef {
char *name;
int r,g,b;
};
cdef cc;
static cdef table[]={
#ifdef __WINDOWS__
{"AQUAMARINE",112, 219, 147},
{"BLACK",0, 0, 0},
{"BLUE", 0, 0, 255},
{"BLUE VIOLET", 159, 95, 159},
{"BROWN", 165, 42, 42},
{"CADET BLUE", 95, 159, 159},
{"CORAL", 255, 127, 0},
{"CORNFLOWER BLUE", 66, 66, 111},
{"CYAN", 0, 255, 255},
{"DARK GREY", 47, 47, 47}, // ?
{"DARK GREEN", 47, 79, 47},
{"DARK OLIVE GREEN", 79, 79, 47},
{"DARK ORCHID", 153, 50, 204},
{"DARK SLATE BLUE", 107, 35, 142},
{"DARK SLATE GREY", 47, 79, 79},
{"DARK TURQUOISE", 112, 147, 219},
{"DIM GREY", 84, 84, 84},
{"FIREBRICK", 142, 35, 35},
{"FOREST GREEN", 35, 142, 35},
{"GOLD", 204, 127, 50},
{"GOLDENROD", 219, 219, 112},
{"GREY", 128, 128, 128},
{"GREEN", 0, 255, 0},
{"GREEN YELLOW", 147, 219, 112},
{"INDIAN RED", 79, 47, 47},
{"KHAKI", 159, 159, 95},
{"LIGHT BLUE", 191, 216, 216},
{"LIGHT GREY", 192, 192, 192},
{"LIGHT STEEL BLUE", 143, 143, 188},
{"LIME GREEN", 50, 204, 50},
{"LIGHT MAGENTA", 255, 0, 255},
{"MAGENTA", 255, 0, 255},
{"MAROON", 142, 35, 107},
{"MEDIUM AQUAMARINE", 50, 204, 153},
{"MEDIUM GREY", 100, 100, 100},
{"MEDIUM BLUE", 50, 50, 204},
{"MEDIUM FOREST GREEN", 107, 142, 35},
{"MEDIUM GOLDENROD", 234, 234, 173},
{"MEDIUM ORCHID", 147, 112, 219},
{"MEDIUM SEA GREEN", 66, 111, 66},
{"MEDIUM SLATE BLUE", 127, 0, 255},
{"MEDIUM SPRING GREEN", 127, 255, 0},
{"MEDIUM TURQUOISE", 112, 219, 219},
{"MEDIUM VIOLET RED", 219, 112, 147},
{"MIDNIGHT BLUE", 47, 47, 79},
{"NAVY", 35, 35, 142},
{"ORANGE", 204, 50, 50},
{"ORANGE RED", 255, 0, 127},
{"ORCHID", 219, 112, 219},
{"PALE GREEN", 143, 188, 143},
{"PINK", 188, 143, 234},
{"PLUM", 234, 173, 234},
{"PURPLE", 176, 0, 255},
{"RED", 255, 0, 0},
{"SALMON", 111, 66, 66},
{"SEA GREEN", 35, 142, 107},
{"SIENNA", 142, 107, 35},
{"SKY BLUE", 50, 153, 204},
{"SLATE BLUE", 0, 127, 255},
{"SPRING GREEN", 0, 255, 127},
{"STEEL BLUE", 35, 107, 142},
{"TAN", 219, 147, 112},
{"THISTLE", 216, 191, 216},
{"TURQUOISE", 173, 234, 234},
{"VIOLET", 79, 47, 79},
{"VIOLET RED", 204, 50, 153},
{"WHEAT", 216, 216, 191},
{"WHITE", 255, 255, 255},
{"YELLOW", 255, 255, 0},
{"YELLOW GREEN", 153, 204, 50},
#endif
#if defined(__GTK__) || defined(__X__)
{"MEDIUM GOLDENROD", 234, 234, 173},
{"MEDIUM FOREST GREEN", 107, 142, 35},
{"LIGHT MAGENTA", 255, 0, 255},
{"MEDIUM GREY", 100, 100, 100},
#endif
{0,0,0,0}
};
int i;
for (i=0;cc=table[i],cc.name!=0;i++)
{
Append(cc.name,new wxColour(cc.r,cc.g,cc.b));
}
}
/*
* Changed by Ian Brown, July 1994.
*
* When running under X, the Colour Database starts off empty. The X server
* is queried for the colour first time after which it is entered into the
* database. This allows our client to use the server colour database which
* is hopefully gamma corrected for the display being used.
*/
wxColour *wxColourDatabase::FindColour(const wxString& colour)
{
wxNode *node = Find((char *) (const char *)colour);
if (node)
return (wxColour *)node->Data();
#ifdef __WINDOWS__
else return NULL;
#endif
#ifdef __GTK__
else {
wxColour *col = new wxColour( colour );
if (!(col->Ok())) {
delete col;
return NULL;
}
Append( colour, col );
return col;
}
#endif
#ifdef __X__
else {
XColor xcolour;
#ifdef __MOTIF__
Display *display = XtDisplay(wxTheApp->topLevel) ;
#endif
#ifdef __XVIEW__
Xv_Screen screen = xv_get(xview_server, SERVER_NTH_SCREEN, 0);
Xv_opaque root_window = xv_get(screen, XV_ROOT);
Display *display = (Display *)xv_get(root_window, XV_DISPLAY);
#endif
/* MATTHEW: [4] Use wxGetMainColormap */
if (!XParseColor(display, wxGetMainColormap(display), colour,&xcolour))
return NULL;
unsigned char r = (unsigned char)(xcolour.red >> 8);
unsigned char g = (unsigned char)(xcolour.green >> 8);
unsigned char b = (unsigned char)(xcolour.blue >> 8);
wxColour *col = new wxColour(r, g, b);
Append(colour, col);
return col;
}
#endif
}
wxString wxColourDatabase::FindName (const wxColour& colour) const
{
unsigned char red = colour.Red ();
unsigned char green = colour.Green ();
unsigned char blue = colour.Blue ();
for (wxNode * node = First (); node; node = node->Next ())
{
wxColour *col = (wxColour *) node->Data ();
if (col->Red () == red && col->Green () == green && col->Blue () == blue)
{
char *found = node->key.string;
if (found)
return wxString(found);
}
}
return wxString(""); // Not Found
}
void
wxInitializeStockObjects (void)
{
wxTheBrushList = new wxBrushList;
wxThePenList = new wxPenList;
wxTheFontList = new wxFontList;
wxTheBitmapList = new wxBitmapList;
#ifdef __MOTIF__
#endif
#ifdef __X__
wxFontPool = new XFontPool;
#endif
wxNORMAL_FONT = new wxFont (12, wxMODERN, wxNORMAL, wxNORMAL);
wxSMALL_FONT = new wxFont (10, wxSWISS, wxNORMAL, wxNORMAL);
wxITALIC_FONT = new wxFont (12, wxROMAN, wxITALIC, wxNORMAL);
wxSWISS_FONT = new wxFont (12, wxSWISS, wxNORMAL, wxNORMAL);
wxRED_PEN = new wxPen ("RED", 1, wxSOLID);
wxCYAN_PEN = new wxPen ("CYAN", 1, wxSOLID);
wxGREEN_PEN = new wxPen ("GREEN", 1, wxSOLID);
wxBLACK_PEN = new wxPen ("BLACK", 1, wxSOLID);
wxWHITE_PEN = new wxPen ("WHITE", 1, wxSOLID);
wxTRANSPARENT_PEN = new wxPen ("BLACK", 1, wxTRANSPARENT);
wxBLACK_DASHED_PEN = new wxPen ("BLACK", 1, wxSHORT_DASH);
wxGREY_PEN = new wxPen ("GREY", 1, wxSOLID);
wxMEDIUM_GREY_PEN = new wxPen ("MEDIUM GREY", 1, wxSOLID);
wxLIGHT_GREY_PEN = new wxPen ("LIGHT GREY", 1, wxSOLID);
wxBLUE_BRUSH = new wxBrush ("BLUE", wxSOLID);
wxGREEN_BRUSH = new wxBrush ("GREEN", wxSOLID);
wxWHITE_BRUSH = new wxBrush ("WHITE", wxSOLID);
wxBLACK_BRUSH = new wxBrush ("BLACK", wxSOLID);
wxTRANSPARENT_BRUSH = new wxBrush ("BLACK", wxTRANSPARENT);
wxCYAN_BRUSH = new wxBrush ("CYAN", wxSOLID);
wxRED_BRUSH = new wxBrush ("RED", wxSOLID);
wxGREY_BRUSH = new wxBrush ("GREY", wxSOLID);
wxMEDIUM_GREY_BRUSH = new wxBrush ("MEDIUM GREY", wxSOLID);
wxLIGHT_GREY_BRUSH = new wxBrush ("LIGHT GREY", wxSOLID);
wxBLACK = new wxColour ("BLACK");
wxWHITE = new wxColour ("WHITE");
wxRED = new wxColour ("RED");
wxBLUE = new wxColour ("BLUE");
wxGREEN = new wxColour ("GREEN");
wxCYAN = new wxColour ("CYAN");
wxLIGHT_GREY = new wxColour ("LIGHT GREY");
wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW);
wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT);
wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS);
}
void
wxDeleteStockObjects (void)
{
DELETEP(wxNORMAL_FONT);
DELETEP(wxSMALL_FONT);
DELETEP(wxITALIC_FONT);
DELETEP(wxSWISS_FONT);
DELETEP(wxRED_PEN);
DELETEP(wxCYAN_PEN);
DELETEP(wxGREEN_PEN);
DELETEP(wxBLACK_PEN);
DELETEP(wxWHITE_PEN);
DELETEP(wxTRANSPARENT_PEN);
DELETEP(wxBLACK_DASHED_PEN);
DELETEP(wxGREY_PEN);
DELETEP(wxMEDIUM_GREY_PEN);
DELETEP(wxLIGHT_GREY_PEN);
DELETEP(wxBLUE_BRUSH);
DELETEP(wxGREEN_BRUSH);
DELETEP(wxWHITE_BRUSH);
DELETEP(wxBLACK_BRUSH);
DELETEP(wxTRANSPARENT_BRUSH);
DELETEP(wxCYAN_BRUSH);
DELETEP(wxRED_BRUSH);
DELETEP(wxGREY_BRUSH);
DELETEP(wxMEDIUM_GREY_BRUSH);
DELETEP(wxLIGHT_GREY_BRUSH);
DELETEP(wxBLACK);
DELETEP(wxWHITE);
DELETEP(wxRED);
DELETEP(wxBLUE);
DELETEP(wxGREEN);
DELETEP(wxCYAN);
DELETEP(wxLIGHT_GREY);
DELETEP(wxSTANDARD_CURSOR);
DELETEP(wxHOURGLASS_CURSOR);
DELETEP(wxCROSS_CURSOR);
}
wxBitmapList::wxBitmapList (void)
{
}
wxBitmapList::~wxBitmapList (void)
{
wxNode *node = First ();
while (node)
{
wxBitmap *bitmap = (wxBitmap *) node->Data ();
wxNode *next = node->Next ();
delete bitmap;
// bitmap->FreeResource(TRUE);
node = next;
}
}
// Pen and Brush lists
wxPenList::~wxPenList (void)
{
wxNode *node = First ();
while (node)
{
wxPen *pen = (wxPen *) node->Data ();
wxNode *next = node->Next ();
delete pen;
// pen->FreeResource(TRUE);
node = next;
}
}
void wxPenList::AddPen (wxPen * pen)
{
Append (pen);
}
void wxPenList::RemovePen (wxPen * pen)
{
DeleteObject (pen);
}
wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, const int width, const int style)
{
for (wxNode * node = First (); node; node = node->Next ())
{
wxPen *each_pen = (wxPen *) node->Data ();
if (each_pen && each_pen->GetVisible() &&
each_pen->GetWidth () == width &&
each_pen->GetStyle () == style &&
each_pen->GetColour ().Red () == colour.Red () &&
each_pen->GetColour ().Green () == colour.Green () &&
each_pen->GetColour ().Blue () == colour.Blue ())
return each_pen;
}
wxPen *pen = new wxPen (colour, width, style);
// Yes, we can return a pointer to this in a later FindOrCreatePen call,
// because we created it within FindOrCreatePen. Safeguards against
// returning a pointer to an automatic variable and hanging on to it
// (dangling pointer).
pen->SetVisible(TRUE);
return pen;
}
wxPen *wxPenList::FindOrCreatePen (const wxString& colour, const int width, const int style)
{
wxColour *the_colour = wxTheColourDatabase->FindColour (colour);
if (the_colour)
return FindOrCreatePen (*the_colour, width, style);
else
return NULL;
}
wxBrushList::~wxBrushList (void)
{
wxNode *node = First ();
while (node)
{
wxBrush *brush = (wxBrush *) node->Data ();
wxNode *next = node->Next ();
delete brush;
node = next;
}
}
void wxBrushList::AddBrush (wxBrush * brush)
{
Append (brush);
}
wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, const int style)
{
for (wxNode * node = First (); node; node = node->Next ())
{
wxBrush *each_brush = (wxBrush *) node->Data ();
if (each_brush && each_brush->GetVisible() &&
each_brush->GetStyle () == style &&
each_brush->GetColour ().Red () == colour.Red () &&
each_brush->GetColour ().Green () == colour.Green () &&
each_brush->GetColour ().Blue () == colour.Blue ())
return each_brush;
}
// Yes, we can return a pointer to this in a later FindOrCreateBrush call,
// because we created it within FindOrCreateBrush. Safeguards against
// returning a pointer to an automatic variable and hanging on to it
// (dangling pointer).
wxBrush *brush = new wxBrush (colour, style);
brush->SetVisible(TRUE);
return brush;
}
wxBrush *wxBrushList::FindOrCreateBrush (const wxString& colour, const int style)
{
wxColour *the_colour = wxTheColourDatabase->FindColour (colour);
if (the_colour)
return FindOrCreateBrush (*the_colour, style);
else
return NULL;
}
void wxBrushList::RemoveBrush (wxBrush * brush)
{
DeleteObject (brush);
}
wxFontList::~wxFontList (void)
{
#ifdef __WINDOWS__
wxNode *node = First ();
while (node)
{
/*
wxFont *font = (wxFont *) node->Data ();
wxNode *next = node->Next ();
delete font;
node = next;
*/
// New for 2.0: don't delete the font (it may be a member
// of a wxDC, for example)
wxFont *font = (wxFont *) node->Data ();
wxNode *next = node->Next ();
// Force the font to be deleted
font->FreeResource(TRUE);
node = next;
}
#endif
}
void wxFontList::AddFont (wxFont * font)
{
Append (font);
}
void wxFontList::RemoveFont (wxFont * font)
{
DeleteObject (font);
}
wxFont *wxFontList::
FindOrCreateFont (const int PointSize, const int FamilyOrFontId, const int Style, const int Weight, const bool underline, const wxString& Face)
{
for (wxNode * node = First (); node; node = node->Next ())
{
wxFont *each_font = (wxFont *) node->Data ();
if (each_font && each_font->GetVisible() && each_font->Ok() &&
each_font->GetPointSize () == PointSize &&
each_font->GetStyle () == Style &&
each_font->GetWeight () == Weight &&
each_font->GetUnderlined () == underline &&
#if defined(__X__) || (defined(__WINDOWS__) && USE_PORTABLE_FONTS_IN_MSW)
each_font->GetFontId () == FamilyOrFontId) /* New font system */
#else
each_font->GetFamily () == FamilyOrFontId &&
(!each_font->GetFaceName() || each_font->GetFaceName() == Face))
#endif
return each_font;
}
wxFont *font = new wxFont (PointSize, FamilyOrFontId, Style, Weight, underline, Face);
font->SetVisible(TRUE);
return font;
}
void wxBitmapList::AddBitmap(wxBitmap *bitmap)
{ Append(bitmap); }
void wxBitmapList::RemoveBitmap(wxBitmap *bitmap)
{ DeleteObject(bitmap); }

361
src/common/glob.inc Normal file
View File

@@ -0,0 +1,361 @@
/*
* File and other globbing (included by wb_utils.cc)
*/
// This file includes:
// wxIsWild(const char *pattern)
// wxMatchWild(const char *pattern, const char *str, bool dot_special)
//
//---------------------------------------------------------------------------------
#ifndef UNIX_GLOB
# ifdef wx_x
# define UNIX_GLOB 1
# else
# define UNIX_GLOB 0
# endif
#endif
#if UNIX_GLOB
# ifdef wx_msw
# error "Can't use Unix file globbing under Windows!"
# endif
#endif
/*************************************************************************
*
* wxIsWild checks whether the pattern contains wildcards, and
* returns TRUE if it does, and FALSE if it does not (or if the
* pattern is NULL -- i.e. no string).
*
* The argument is:
*
* 1) pattern - a character string
*/
bool
wxIsWild (const char *pattern)
{
while (*pattern)
{
switch (*pattern++)
{
case '?':
case '*':
#if UNIX_GLOB
case '[':
case '{': /* } */
#endif
return TRUE;
#if UNIX_GLOB
case '\\':
if (!*pattern++)
return FALSE;
#endif
} /* switch() */
} /* while() */
return FALSE;
}
#if UNIX_GLOB
// Unix Glob()
//
// Pattern Function
// -----------------------------------------------------
// '*' = match 0 or more occurances of anything
// "[abc]" = match anyof "abc" (ranges supported)
// "{xx,yy,zz}" = match anyof "xx", "yy", or "zz"
// '?' = match any character
//
// '\' is used to "escape" special characters
// Recursive
bool
wxMatchWild (const char *pattern, const char *str, bool dot_special)
{
char c;
const char *cp;
bool done = FALSE, ret_code, ok;
// Below is for vi fans
const char OB = '{', CB = '}';
#if 0
if (strcmp(pattern, "*.*") == 0)
pattern = "*"; // Hack for MS-DOS compat.
#endif
// dot_special means '.' only matches '.'
if (dot_special && *str == '.' && *pattern != *str)
return FALSE;
while ((*pattern != '\0') && (!done) && (((*str == '\0') &&
((*pattern == OB) || (*pattern == '*'))) || (*str != '\0')))
{
switch (*pattern)
{
case '\\':
pattern++;
if (*pattern != '\0')
pattern++;
break;
case '*':
pattern++;
ret_code = FALSE;
while ((*str != '\0') && (!(ret_code = wxMatchWild (pattern, str++, FALSE))));
if (ret_code)
{
while (*str != '\0')
str++;
while (*pattern != '\0')
pattern++;
}
break;
case '[':
pattern++;
repeat:
if ((*pattern == '\0') || (*pattern == ']'))
{
done = TRUE;
break;
}
if (*pattern == '\\')
{
pattern++;
if (*pattern == '\0')
{
done = TRUE;
break;
}
}
if (*(pattern + 1) == '-')
{
c = *pattern;
pattern += 2;
if (*pattern == ']')
{
done = TRUE;
break;
}
if (*pattern == '\\')
{
pattern++;
if (*pattern == '\0')
{
done = TRUE;
break;
}
}
if ((*str < c) || (*str > *pattern))
{
pattern++;
goto repeat;
}
}
else if (*pattern != *str)
{
pattern++;
goto repeat;
}
pattern++;
while ((*pattern != ']') && (*pattern != '\0'))
{
if ((*pattern == '\\') && (*(pattern + 1) != '\0'))
pattern++;
pattern++;
} // while()
if (*pattern != '\0')
{
pattern++, str++;
}
break;
case '?':
pattern++;
str++;
break;
case OB:
pattern++;
while ((*pattern != CB) && (*pattern != '\0'))
{
cp = str;
ok = TRUE;
while (ok && (*cp != '\0') && (*pattern != '\0') &&
(*pattern != ',') && (*pattern != CB))
{
if (*pattern == '\\')
pattern++;
ok = (*pattern++ == *cp++);
} // while()
if (*pattern == '\0')
{
ok = FALSE;
done = TRUE;
break;
}
else if (ok)
{
str = cp;
while ((*pattern != CB) && (*pattern != '\0'))
{
if (*++pattern == '\\')
{
if (*++pattern == CB)
pattern++;
}
} // while()
}
else
{
while (*pattern != CB && *pattern != ',' && *pattern != '\0')
{
if (*++pattern == '\\')
{
if (*++pattern == CB || *pattern == ',')
pattern++;
}
} // while()
}
if (*pattern != '\0')
pattern++;
} // while()
break;
default:
if (*str == *pattern)
{
str++, pattern++;
}
else
{
done = TRUE;
}
} // switch()
} // while()
while (*pattern == '*')
pattern++;
return ((*str == '\0') && (*pattern == '\0'));
}
#else /* MS-DOS/Windows glob() */
/*************************************************************************
*
* wxMatchWild matches the given pattern string against
* a text string, and returns TRUE if it matches, FALSE otherwise.
*
* A match means that the entire text string is used up in the matching.
* The pattern can contain the following wildcards.
*
* * -- matches any sequence of characters
* ? -- matches one character
*
* If one or other or both of the string arguments to wxMatchWild function is
* NULL (i.e. there isn't a string), then the function returns FALSE.
*
*/
static bool wxPatternMatch (const char *pattern, const char *text, size_t i, size_t j);
// @@@@ dotSpecial is ignored by MS-DOS
bool
wxMatchWild (const char *pattern, const char *text, bool /* dotSpecial */ )
{
if (pattern == NULL || text == NULL || *pattern == '\0' || *text == '\0')
return FALSE;
return wxPatternMatch (pattern, text, 0, 0);
}
/*************************************************************************
*
* wxPatternMatch does the work for wxMatchWild. wxPatternMatch matches
* the given pattern string against a text string, and returns TRUE if
* it matches, FALSE otherwise. It is assumed that the string arguments
* to wxPatternMatch exist.
*
* A match means that the entire text string is used up in the matching.
* The pattern can contain the following wildcards.
*
* * -- matches any sequence of characters
* ? -- matches one character
*
* wxPatternMatch works by going down the pattern trying to match the
* the same index character in the pattern and string arrays, and stops
* when the end of the pattern or text string is reached. However, if a
* '*' wildcard is met, the algorithm checks to see whether the remaining
* pattern (after the wildcard) matches the rest of the text (i.e. the
* wxPatternMatch function is called recursively).
*/
// Recursive
static bool
wxPatternMatch (const char *pattern, const char *text, size_t i, size_t j)
{
size_t pattern_length = strlen (pattern);
size_t text_length = strlen (text);
bool match = FALSE;
#ifdef wx_msw
// MS-DOS file system is case INDEPENDENT
# define EQU(x,y) (wxToLower(x) == wxToLower(y))
#else
# define EQU(x,y) ((x) == (y))
#endif
while (j < pattern_length && i < text_length)
{
if (EQU(text[i], pattern[j]) || pattern[j] == '?')
{
match = TRUE;
i++, j++;
}
else if (pattern[j] == '*')
{
// If pattern ends in '*'
if (++j == pattern_length)
{
match = TRUE;
i = text_length;
}
else
{
match = FALSE;
// after wildcard check to see whether rest of pattern matches
// up with rest of text
while (i < text_length && match != TRUE)
{
match = wxPatternMatch (pattern, text, i, j);
i++;
}
// text index is decremented so that it points to where
// the text string starts to match the rest of the pattern
i--;
}
}
else if (! EQU(text[i], pattern[j]))
{
j = pattern_length;
match = FALSE;
}
}
if (j == pattern_length && i == text_length && match == TRUE)
{
return TRUE;
}
else
// special case where pattern and text are the same except that pattern
// also only has '*' wildcards on the end
if (i == text_length && pattern[j] == '*' && match == TRUE)
{
for (; j < pattern_length; j++)
{
if (pattern[j] != '*')
return FALSE;
}
return TRUE;
}
else
{
return FALSE;
}
}
#endif /* UNIX_GLOB */
//-----------------------------------------------------------------------------

350
src/common/hash.cpp Normal file
View File

@@ -0,0 +1,350 @@
/////////////////////////////////////////////////////////////////////////////
// Name: hash.cpp
// Purpose: wxHashTable implementation
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "hash.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/list.h"
#endif
#include "wx/hash.h"
#include <string.h>
#include <stdarg.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxHashTable, wxObject)
#endif
wxHashTable::wxHashTable (const int the_key_type, const int size)
{
n = size;
current_position = -1;
current_node = NULL;
key_type = the_key_type;
hash_table = new wxList *[size];
int i;
for (i = 0; i < size; i++)
hash_table[i] = NULL;
}
wxHashTable::~wxHashTable (void)
{
int i;
for (i = 0; i < n; i++)
if (hash_table[i])
delete hash_table[i];
delete[] hash_table;
}
bool wxHashTable::Create(const int the_key_type, const int size)
{
n = size;
current_position = -1;
current_node = NULL;
key_type = the_key_type;
if (hash_table)
delete[] hash_table;
hash_table = new wxList *[size];
int i;
for (i = 0; i < size; i++)
hash_table[i] = NULL;
return TRUE;
}
void wxHashTable::Put (const long key, const long value, wxObject * object)
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_INTEGER);
hash_table[position]->Append (value, object);
}
void wxHashTable::Put (const long key, const char *value, wxObject * object)
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_INTEGER);
hash_table[position]->Append (value, object);
}
void wxHashTable::Put (const long key, wxObject * object)
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_INTEGER);
hash_table[position]->Append (k, object);
}
void wxHashTable::Put (const char *key, wxObject * object)
{
int position = (int) (MakeKey (key) % n);
if (!hash_table[position])
hash_table[position] = new wxList (wxKEY_STRING);
hash_table[position]->Append (key, object);
}
wxObject *wxHashTable::Get (const long key, const long value) const
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
return node->Data ();
else
return NULL;
}
}
wxObject *wxHashTable::Get (const long key, const char *value) const
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
return node->Data ();
else
return NULL;
}
}
wxObject *wxHashTable::Get (const long key) const
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (k);
return node ? node->Data () : (wxObject*)NULL;
}
}
wxObject *wxHashTable::Get (const char *key) const
{
int position = (int) (MakeKey (key) % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (key);
return node ? node->Data () : (wxObject*)NULL;
}
}
wxObject *wxHashTable::Delete (const long key)
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (k);
if (node)
{
wxObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
wxObject *wxHashTable::Delete (const char *key)
{
int position = (int) (MakeKey (key) % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (key);
if (node)
{
wxObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
wxObject *wxHashTable::Delete (const long key, const int value)
{
// Should NEVER be
long k = (long) key;
if (k < 0)
k = -k;
int position = (int) (k % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
{
wxObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
wxObject *wxHashTable::Delete (const long key, const char *value)
{
int position = (int) (key % n);
if (!hash_table[position])
return NULL;
else
{
wxNode *node = hash_table[position]->Find (value);
if (node)
{
wxObject *data = node->Data ();
delete node;
return data;
}
else
return NULL;
}
}
long wxHashTable::MakeKey (const char *string) const
{
long int_key = 0;
while (*string)
int_key += (unsigned char) *string++;
return int_key;
}
void wxHashTable::BeginFind (void)
{
current_position = -1;
current_node = NULL;
}
wxNode *wxHashTable::Next (void)
{
wxNode *found = NULL;
bool end = FALSE;
while (!end && !found)
{
if (!current_node)
{
current_position++;
if (current_position >= n)
{
current_position = -1;
current_node = NULL;
end = TRUE;
}
else
{
if (hash_table[current_position])
{
current_node = hash_table[current_position]->First ();
found = current_node;
}
}
}
else
{
current_node = current_node->Next ();
found = current_node;
}
}
return found;
}
void wxHashTable::DeleteContents (const bool flag)
{
int i;
for (i = 0; i < n; i++)
{
if (hash_table[i])
hash_table[i]->DeleteContents (flag);
}
}
void wxHashTable::Clear (void)
{
int i;
for (i = 0; i < n; i++)
{
if (hash_table[i])
hash_table[i]->Clear ();
}
}

35
src/common/helpbase.cpp Normal file
View File

@@ -0,0 +1,35 @@
/////////////////////////////////////////////////////////////////////////////
// Name: helpbase.cpp
// Purpose: Help system base classes
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "helpbase.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#endif
#include "wx/helpbase.h"
#if USE_HELP
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxHelpControllerBase, wxObject)
#endif
#endif // USE_HELP

538
src/common/intl.cpp Normal file
View File

@@ -0,0 +1,538 @@
/////////////////////////////////////////////////////////////////////////////
// Name: intl.cpp
// Purpose: Internationalization and localisation for wxWindows
// Author: Vadim Zeitlin
// Modified by:
// Created: 29/01/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declaration
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "intl.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// standard headers
#include <locale.h>
// wxWindows
#include "wx/defs.h"
#include "wx/string.h"
#include "wx/intl.h"
#include "wx/file.h"
#include "wx/log.h"
#include "wx/utils.h"
#include <stdlib.h>
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// magic number identifying the .mo format file
const uint32 MSGCATALOG_MAGIC = 0x950412de;
const uint32 MSGCATALOG_MAGIC_SW = 0xde120495;
// extension of ".mo" files
#define MSGCATALOG_EXTENSION ".mo"
// ----------------------------------------------------------------------------
// global functions
// ----------------------------------------------------------------------------
// suppress further error messages about missing translations
// (if you don't have one catalog file, you wouldn't like to see the
// error message for each string in it, so normally it's given only
// once)
void wxSuppressTransErrors();
// restore the logging
void wxRestoreTransErrors();
// get the current state
bool wxIsLoggingTransErrors();
// get the current locale object (## may be NULL!)
extern wxLocale *wxSetLocale(wxLocale *pLocale);
// ----------------------------------------------------------------------------
// wxMsgCatalog corresponds to one disk-file message catalog.
//
// This is a "low-level" class and is used only by wxLocale (that's why
// it's designed to be stored in a linked list)
// ----------------------------------------------------------------------------
class wxMsgCatalog
{
public:
// ctor & dtor
wxMsgCatalog();
~wxMsgCatalog();
// load the catalog from disk (szDirPrefix corresponds to language)
bool Load(const char *szDirPrefix, const char *szName);
bool IsLoaded() const { return m_pData != NULL; }
// get name of the catalog
const char *GetName() const { return m_pszName; }
// get the translated string: returns NULL if not found
const char *GetString(const char *sz) const;
// public variable pointing to the next element in a linked list (or NULL)
wxMsgCatalog *m_pNext;
private:
// this implementation is binary compatible with GNU gettext() version 0.10
// an entry in the string table
struct wxMsgTableEntry
{
uint32 nLen; // length of the string
uint32 ofsString; // pointer to the string
};
// header of a .mo file
struct wxMsgCatalogHeader
{
uint32 magic, // offset +00: magic id
revision, // +04: revision
numStrings; // +08: number of strings in the file
uint32 ofsOrigTable, // +0C: start of original string table
ofsTransTable; // +10: start of translated string table
uint32 nHashSize, // +14: hash table size
ofsHashTable; // +18: offset of hash table start
};
// all data is stored here, NULL if no data loaded
uint8 *m_pData;
// data description
uint32 m_numStrings, // number of strings in this domain
m_nHashSize; // number of entries in hash table
uint32 *m_pHashTable; // pointer to hash table
wxMsgTableEntry *m_pOrigTable, // pointer to original strings
*m_pTransTable; // translated
const char *StringAtOfs(wxMsgTableEntry *pTable, uint32 index) const
{ return (const char *)(m_pData + Swap(pTable[index].ofsString)); }
// utility functions
// calculate the hash value of given string
static inline uint32 GetHash(const char *sz);
// big<->little endian
inline uint32 Swap(uint32 ui) const;
// internal state
bool HasHashTable() const // true if hash table is present
{ return m_nHashSize > 2 && m_pHashTable != NULL; }
bool m_bSwapped; // wrong endianness?
char *m_pszName; // name of the domain
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxMsgCatalog class
// ----------------------------------------------------------------------------
// calculate hash value using the so called hashpjw function by P.J. Weinberger
// [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools]
uint32 wxMsgCatalog::GetHash(const char *sz)
{
#define HASHWORDBITS 32 // the length of uint32
uint32 hval = 0;
uint32 g;
while ( *sz != '\0' ) {
hval <<= 4;
hval += (uint32)*sz++;
g = hval & ((uint32)0xf << (HASHWORDBITS - 4));
if ( g != 0 ) {
hval ^= g >> (HASHWORDBITS - 8);
hval ^= g;
}
}
return hval;
}
// swap the 2 halves of 32 bit integer if needed
uint32 wxMsgCatalog::Swap(uint32 ui) const
{
return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
((ui >> 8) & 0xff00) | (ui >> 24)
: ui;
}
wxMsgCatalog::wxMsgCatalog()
{
m_pData = NULL;
m_pszName = NULL;
}
wxMsgCatalog::~wxMsgCatalog()
{
DELETEA(m_pData);
DELETEA(m_pszName);
}
class NoTransErr
{
public:
NoTransErr() { wxSuppressTransErrors(); }
~NoTransErr() { wxRestoreTransErrors(); }
};
// open disk file and read in it's contents
bool wxMsgCatalog::Load(const char *szDirPrefix, const char *szName)
{
// search order (assume language 'foo') is
// 1) $LC_PATH/foo/LC_MESSAGES (if LC_PATH set)
// 2) ./foo/LC_MESSAGES
// 3) ./foo
// 4) . (Added by JACS)
//
// under UNIX we search also in:
// 5) /usr/share/locale/foo/LC_MESSAGES (Linux)
// 6) /usr/lib/locale/foo/LC_MESSAGES (Solaris)
#define MSG_PATH FILE_SEP_PATH + "LC_MESSAGES" PATH_SEP
wxString strPath("");
const char *pszLcPath = getenv("LC_PATH");
if ( pszLcPath != NULL )
strPath += pszLcPath + wxString(szDirPrefix) + MSG_PATH; // (1)
// NB: '<<' is unneeded between too literal strings:
// they are concatenated at compile time
strPath += "./" + wxString(szDirPrefix) + MSG_PATH // (2)
+ "./" + szDirPrefix + FILE_SEP_PATH + PATH_SEP // (3)
+ "." + PATH_SEP
#ifdef __UNIX__
"/usr/share/locale/" + szDirPrefix + MSG_PATH // (5)
"/usr/lib/locale/" + szDirPrefix + MSG_PATH // (6)
#endif //UNIX
;
wxString strFile = szName;
strFile += MSGCATALOG_EXTENSION;
// don't give translation errors here because the wxstd catalog might
// not yet be loaded (and it's normal)
//
// (we're using an object because we have several return paths)
NoTransErr noTransErr;
wxLogVerbose("looking for catalog '%s' in path '%s'.",
szName, strPath.c_str());
wxString strFullName;
if ( !wxFindFileInPath(&strFullName, strPath, strFile) ) {
wxLogWarning("catalog file for domain '%s' not found.", szName);
return FALSE;
}
// open file
wxLogVerbose("using catalog '%s' from '%s'.",
szName, strFullName.c_str());
wxFile fileMsg(strFullName);
if ( !fileMsg.IsOpened() )
return FALSE;
// get the file size
off_t nSize = fileMsg.Length();
if ( nSize == ofsInvalid )
return FALSE;
// read the whole file in memory
m_pData = new uint8[nSize];
if ( fileMsg.Read(m_pData, nSize) != nSize ) {
DELETEA(m_pData);
m_pData = NULL;
return FALSE;
}
// examine header
bool bValid = (size_t)nSize > sizeof(wxMsgCatalogHeader);
wxMsgCatalogHeader *pHeader;
if ( bValid ) {
pHeader = (wxMsgCatalogHeader *)m_pData;
// we'll have to swap all the integers if it's true
m_bSwapped = pHeader->magic == MSGCATALOG_MAGIC_SW;
// check the magic number
bValid = m_bSwapped || pHeader->magic == MSGCATALOG_MAGIC;
}
if ( !bValid ) {
// it's either too short or has incorrect magic number
wxLogWarning("'%s' is not a valid message catalog.", strFullName.c_str());
DELETEA(m_pData);
m_pData = NULL;
return FALSE;
}
// initialize
m_numStrings = Swap(pHeader->numStrings);
m_pOrigTable = (wxMsgTableEntry *)(m_pData +
Swap(pHeader->ofsOrigTable));
m_pTransTable = (wxMsgTableEntry *)(m_pData +
Swap(pHeader->ofsTransTable));
m_nHashSize = Swap(pHeader->nHashSize);
m_pHashTable = (uint32 *)(m_pData + Swap(pHeader->ofsHashTable));
m_pszName = new char[strlen(szName) + 1];
strcpy(m_pszName, szName);
// everything is fine
return TRUE;
}
// search for a string
const char *wxMsgCatalog::GetString(const char *szOrig) const
{
if ( szOrig == NULL )
return NULL;
if ( HasHashTable() ) { // use hash table for lookup if possible
uint32 nHashVal = GetHash(szOrig);
uint32 nIndex = nHashVal % m_nHashSize;
uint32 nIncr = 1 + (nHashVal % (m_nHashSize - 2));
while ( TRUE ) {
uint32 nStr = Swap(m_pHashTable[nIndex]);
if ( nStr == 0 )
return NULL;
if ( strcmp(szOrig, StringAtOfs(m_pOrigTable, nStr - 1)) == 0 )
return StringAtOfs(m_pTransTable, nStr - 1);
if ( nIndex >= m_nHashSize - nIncr)
nIndex -= m_nHashSize - nIncr;
else
nIndex += nIncr;
}
}
else { // no hash table: use default binary search
uint32 bottom = 0,
top = m_numStrings,
current;
while ( bottom < top ) {
current = (bottom + top) / 2;
int res = strcmp(szOrig, StringAtOfs(m_pOrigTable, current));
if ( res < 0 )
top = current;
else if ( res > 0 )
bottom = current + 1;
else // found!
return StringAtOfs(m_pTransTable, current);
}
}
// not found
return NULL;
}
// ----------------------------------------------------------------------------
// wxLocale
// ----------------------------------------------------------------------------
// NB: ctor has (desired) side effect of changing current locale
wxLocale::wxLocale(const char *szName,
const char *szShort,
const char *szLocale,
bool bLoadDefault)
: m_strLocale(szName), m_strShort(szShort)
{
// change current locale (default: same as long name)
if ( szLocale == NULL )
szLocale = szName;
m_pszOldLocale = setlocale(LC_ALL, szLocale);
if ( m_pszOldLocale == NULL )
wxLogError("locale '%s' can not be set.", szLocale);
// the short name will be used to look for catalog files as well,
// so we need something here
if ( m_strShort.IsEmpty() ) {
// #### I don't know how these 2 letter abbreviations are formed,
// this wild guess is almost surely wrong
m_strShort = wxToLower(szLocale[0]) + wxToLower(szLocale[1]);
}
// save the old locale to be able to restore it later
m_pOldLocale = wxSetLocale(this);
// load the default catalog with wxWindows standard messages
m_pMsgCat = NULL;
if ( bLoadDefault )
AddCatalog("wxstd");
}
// clean up
wxLocale::~wxLocale()
{
// free memory
wxMsgCatalog *pTmpCat;
while ( m_pMsgCat != NULL ) {
pTmpCat = m_pMsgCat;
m_pMsgCat = m_pMsgCat->m_pNext;
delete pTmpCat;
}
// restore old locale
wxSetLocale(m_pOldLocale);
setlocale(LC_ALL, m_pszOldLocale);
}
// get the translation of given string in current locale
const char *wxLocale::GetString(const char *szOrigString,
const char *szDomain) const
{
wxASSERT( szOrigString != NULL ); // would be pretty silly
const char *pszTrans = NULL;
wxMsgCatalog *pMsgCat;
if ( szDomain != NULL ) {
pMsgCat = FindCatalog(szDomain);
// does the catalog exist?
if ( pMsgCat != NULL )
pszTrans = pMsgCat->GetString(szOrigString);
}
else {
// search in all domains
for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext ) {
pszTrans = pMsgCat->GetString(szOrigString);
if ( pszTrans != NULL ) // take the first found
break;
}
}
if ( pszTrans == NULL ) {
if ( wxIsLoggingTransErrors() ) {
// suppress further error messages
// (do it before LogWarning to prevent infinite recursion!)
wxSuppressTransErrors();
if ( szDomain != NULL )
wxLogWarning("string '%s' not found in domain '%s' for locale '%s'.",
szOrigString, szDomain, m_strLocale.c_str());
else
wxLogWarning("string '%s' not found in locale '%s'.",
szOrigString, m_strLocale.c_str());
}
return szOrigString;
}
else
return pszTrans;
}
// find catalog by name in a linked list, return NULL if !found
wxMsgCatalog *wxLocale::FindCatalog(const char *szDomain) const
{
// linear search in the linked list
wxMsgCatalog *pMsgCat;
for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext ) {
if ( Stricmp(pMsgCat->GetName(), szDomain) == 0 )
return pMsgCat;
}
return NULL;
}
// check if the given catalog is loaded
bool wxLocale::IsLoaded(const char *szDomain) const
{
return FindCatalog(szDomain) != NULL;
}
// add a catalog to our linked list
bool wxLocale::AddCatalog(const char *szDomain)
{
wxMsgCatalog *pMsgCat = new wxMsgCatalog;
if ( pMsgCat->Load(m_strShort, szDomain) ) {
// add it to the head of the list so that in GetString it will
// be searched before the catalogs added earlier
pMsgCat->m_pNext = m_pMsgCat;
m_pMsgCat = pMsgCat;
return TRUE;
}
else {
// don't add it because it couldn't be loaded anyway
delete pMsgCat;
return FALSE;
}
}
// ----------------------------------------------------------------------------
// global functions and variables
// ----------------------------------------------------------------------------
// translation errors logging
// --------------------------
static bool gs_bGiveTransErrors = TRUE;
void wxSuppressTransErrors()
{
gs_bGiveTransErrors = FALSE;
}
void wxRestoreTransErrors()
{
gs_bGiveTransErrors = TRUE;
}
bool wxIsLoggingTransErrors()
{
return gs_bGiveTransErrors;
}
// retrieve/change current locale
// ------------------------------
// the current locale object
wxLocale *g_pLocale = NULL;
wxLocale *wxGetLocale()
{
return g_pLocale;
}
wxLocale *wxSetLocale(wxLocale *pLocale)
{
wxLocale *pOld = g_pLocale;
g_pLocale = pLocale;
return pOld;
}

35
src/common/ipcbase.cpp Normal file
View File

@@ -0,0 +1,35 @@
/////////////////////////////////////////////////////////////////////////////
// Name: ipcbase.cpp
// Purpose: IPC base classes
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "ipcbase.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#endif
#include "wx/ipcbase.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxServerBase, wxObject)
IMPLEMENT_CLASS(wxClientBase, wxObject)
IMPLEMENT_CLASS(wxConnectionBase, wxObject)
#endif

1747
src/common/layout.cpp Normal file

File diff suppressed because it is too large Load Diff

640
src/common/list.cpp Normal file
View File

@@ -0,0 +1,640 @@
/////////////////////////////////////////////////////////////////////////////
// Name: list.cpp
// Purpose: wxList implementation
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "list.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include "wx/list.h"
#include "wx/utils.h"
#endif
// Sun CC compatibility (interference with xview/pkg.h, apparently...)
#if defined(SUN_CC) && defined(__XVIEW__)
#undef va_start
#undef va_end
#undef va_arg
#undef va_list
#endif
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxNode, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxList, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxStringList, wxList)
#endif
wxNode::wxNode (wxList * the_list, wxNode * last_one, wxNode * next_one,
wxObject * object)
{
data = object;
previous = last_one;
next = next_one;
list = the_list;
key.string = NULL;
if (previous)
previous->next = this;
if (next)
next->previous = this;
}
// Keyed constructor
wxNode::wxNode (wxList * the_list, wxNode * last_one, wxNode * next_one,
wxObject * object, long the_key)
{
data = object;
previous = last_one;
next = next_one;
list = the_list;
key.integer = the_key;
if (previous)
previous->next = this;
if (next)
next->previous = this;
}
wxNode::wxNode (wxList * the_list, wxNode * last_one, wxNode * next_one,
wxObject * object, const char *the_key)
{
data = object;
previous = last_one;
next = next_one;
list = the_list;
key.string = copystring (the_key);
if (previous)
previous->next = this;
if (next)
next->previous = this;
}
wxNode::~wxNode (void)
{
if (list)
list->n--;
if (list && list->destroy_data)
delete data;
if (list && list->key_type == wxKEY_STRING && key.string)
delete[]key.string;
// Make next node point back to the previous node from here
if (next)
next->previous = previous;
else if (list)
// If there's a new end of list (deleting the last one)
// make sure the list knows about it.
list->last_node = previous;
// Make the previous node point to the next node from here
if (previous)
previous->next = next;
// Or if no previous node (start of list), make sure list points at
// the next node which becomes the first!.
else if (list)
list->first_node = next;
}
wxList::wxList (void)
{
first_node = NULL;
last_node = NULL;
n = 0;
destroy_data = 0;
key_type = wxKEY_NONE;
}
wxList::wxList (const int N, wxObject * Objects[])
{
wxNode *last = NULL;
int i;
for (i = 0; i < N; i++)
{
wxNode *next = new wxNode (this, last, NULL, Objects[i]);
last = next;
if (i == 0)
first_node = next;
}
last_node = last;
n = N;
key_type = wxKEY_NONE;
}
wxList::wxList (const unsigned int the_key_type)
{
n = 0;
destroy_data = 0;
first_node = NULL;
last_node = NULL;
key_type = the_key_type;
}
// Variable argument list, terminated by a zero
wxList::wxList (wxObject * first_one...)
{
// #ifndef __SGI__
va_list ap;
va_start (ap, first_one);
wxNode *last = new wxNode (this, NULL, NULL, first_one);
first_node = last;
n = 1;
for (;;)
{
wxObject *object = va_arg (ap, wxObject *);
// if (object == NULL) // Doesn't work in Windows -- segment is non-zero for NULL!
#ifdef __WINDOWS__
if ((int) object == 0)
#else
if ((long) object == 0)
#endif
break;
else
{
wxNode *node = new wxNode (this, last, NULL, object);
last = node;
n++;
}
}
last_node = last;
va_end (ap);
destroy_data = 0;
key_type = wxKEY_NONE;
/*
#else
fprintf (stderr, "Error: cannot use variable-argument functions on SGI!\n");
#endif
*/
}
wxList::~wxList (void)
{
wxNode *each = first_node;
while (each)
{
wxNode *next = each->Next ();
delete each;
each = next;
}
}
#ifdef USE_STORABLE_CLASSES
wxList::wxList( istream &stream, char *WXUNUSED(data) )
{
char buf[200];
unsigned int num;
stream.read( (char*)(&num), sizeof(num) );
for (unsigned int i = 0; i < num; i++)
{
int len;
stream.read( (char*)(&len), sizeof(len) );
stream.read( (char*)(&buf), len );
buf[len] = 0;
Append( wxCreateStoredObject( buf, stream, NULL ) );
};
};
void wxList::StoreObject( ostream &stream )
{
unsigned int num = Number();
stream.write( (char*)(&num), sizeof(num) );
wxNode *node = First();
while (node)
{
wxObject *obj = (wxObject*) node->Data();
wxClassInfo *obj_info = obj->GetClassInfo();
int len = strlen(obj_info->className);
stream.write( (char*)(&len), sizeof(len) );
stream.write( obj_info->className, len );
obj->StoreObject( stream );
node = node->Next();
};
};
#endif
wxNode *wxList::Append(wxObject *object)
{
wxNode *node = new wxNode(this, last_node, NULL, object);
if (!first_node)
first_node = node;
last_node = node;
n ++;
return node;
}
wxNode *wxList::Nth (const int i) const
{
int j = 0;
for (wxNode * current = First (); current; current = current->Next ())
{
if (j++ == i)
return current;
}
return NULL; // No such element
}
wxNode *wxList::Find (const long key) const
{
wxNode *current = First();
while (current)
{
if (current->key.integer == key)
return current;
current = current->Next();
}
return NULL; // Not found!
}
wxNode *wxList::Find (const char *key) const
{
wxNode *current = First();
while (current)
{
if (!current->key.string)
{
wxFatalError ("wxList: string key not present, probably did not Append correctly!");
break;
}
if (strcmp (current->key.string, key) == 0)
return current;
current = current->Next();
}
return NULL; // Not found!
}
wxNode *wxList::Member (wxObject * object) const
{
for (wxNode * current = First (); current; current = current->Next ())
{
wxObject *each = current->Data ();
if (each == object)
return current;
}
return NULL;
}
bool wxList::DeleteNode (wxNode * node)
{
if (node)
{
delete node;
return TRUE;
}
return FALSE;
}
bool wxList::DeleteObject (wxObject * object)
{
// Search list for object
for (wxNode * current = first_node; current; current = current->Next ())
{
if (current->Data () == object)
{
delete current;
return TRUE;
}
}
return FALSE; // Did not find the object
}
// Insert new node at front of list
wxNode *wxList::Insert (wxObject * object)
{
wxNode *node = new wxNode (this, NULL, First (), object);
first_node = node;
if (!(node->Next ()))
last_node = node;
n++;
return node;
}
// Insert new node before given node.
wxNode *wxList::Insert (wxNode * position, wxObject * object)
{
wxNode *prev = NULL;
if (position)
prev = position->Previous ();
wxNode *node = new wxNode (this, prev, position, object);
if (!first_node)
{
first_node = node;
last_node = node;
}
if (!prev)
first_node = node;
n++;
return node;
}
// Keyed append
wxNode *wxList::Append (const long key, wxObject * object)
{
wxNode *node = new wxNode (this, last_node, NULL, object, key);
if (!first_node)
first_node = node;
last_node = node;
n++;
return node;
}
wxNode *wxList::Append (const char *key, wxObject * object)
{
wxNode *node = new wxNode (this, last_node, NULL, object, key);
if (!first_node)
first_node = node;
last_node = node;
n++;
return node;
}
void wxList::Clear (void)
{
wxNode *current = first_node;
while (current)
{
wxNode *next = current->Next ();
delete current;
current = next;
}
first_node = NULL;
last_node = NULL;
n = 0;
}
//Executes function F with all items present in the list
void wxList::ForEach(wxListIterateFunction F)
{
wxNode *each = first_node;
while (each)
{ (*F)( each->Data ());
each = each->Next();
}
}
// Returns a pointer to the item which returns TRUE with function F
// or NULL if no such item found
wxObject *wxList::FirstThat(wxListIterateFunction F)
{
wxNode *each = first_node;
while (each)
{ if ((*F)( each->Data ())) return each->Data();
each = each->Next();
}
return NULL;
}
// Like FirstThat, but proceeds from the end backward
wxObject *wxList::LastThat(wxListIterateFunction F)
{
wxNode *each = last_node;
while (each)
{ if ((*F)( each->Data ())) return each->Data();
each = each->Previous();
}
return NULL;
}
// (stefan.hammes@urz.uni-heidelberg.de)
//
// function for sorting lists. the concept is borrowed from 'qsort'.
// by giving a sort function, arbitrary lists can be sorted.
// method:
// - put wxObject pointers into an array
// - sort the array with qsort
// - put back the sorted wxObject pointers into the list
//
// CAVE: the sort function receives pointers to wxObject pointers (wxObject **),
// so dereference right!
// EXAMPLE:
// int listcompare(const void *arg1, const void *arg2)
// {
// return(compare(**(wxString **)arg1,
// **(wxString **)arg2));
// }
//
// void main()
// {
// wxList list;
//
// list.Append(new wxString("DEF"));
// list.Append(new wxString("GHI"));
// list.Append(new wxString("ABC"));
// list.Sort(listcompare);
// }
void wxList::Sort(const wxSortCompareFunction compfunc)
{
// allocate an array for the wxObject pointers of the list
const size_t num = Number();
wxObject **objArray = new wxObject *[num];
wxObject **objPtr = objArray;
// go through the list and put the pointers into the array
wxNode *node = First();
while(node!=NULL){
*objPtr++ = node->Data();
node = node->Next();
}
// sort the array
qsort((void *)objArray,num,sizeof(wxObject *),compfunc);
// put the sorted pointers back into the list
objPtr = objArray;
node = First();
while(node!=NULL){
node->SetData(*objPtr++);
node = node->Next();
}
// free the array
delete[] objArray;
}
/*
* String list
*
*/
wxStringList::wxStringList (void):
wxList ()
{
}
// Variable argument list, terminated by a zero
// Makes new storage for the strings
wxStringList::wxStringList (const char *first...)
{
// #ifndef __SGI__
n = 0;
destroy_data = 0;
key_type = wxKEY_NONE;
first_node = NULL;
last_node = NULL;
if (!first)
return;
va_list ap;
va_start (ap, first);
wxNode *last = new wxNode (this, NULL, NULL, (wxObject *) copystring (first));
first_node = last;
n = 1;
for (;;)
{
char *s = va_arg (ap, char *);
// if (s == NULL)
#ifdef __WINDOWS__
if ((int) s == 0)
#else
if ((long) s == 0)
#endif
break;
else
{
wxNode *node = new wxNode (this, last, NULL, (wxObject *) copystring (s));
last = node;
n++;
}
}
last_node = last;
va_end (ap);
/*
#else
fprintf (stderr, "Error: cannot use variable-argument functions on SGI!\n");
#endif
*/
}
wxStringList::~wxStringList (void)
{
wxNode *each = first_node;
while (each)
{
char *s = (char *) each->Data ();
delete[]s;
wxNode *next = each->Next ();
delete each;
each = next;
}
}
wxNode *wxStringList::Add (const char *s)
{
return Append ((wxObject *) (copystring (s)));
}
void wxStringList::Delete (const char *s)
{
for (wxNode * node = First (); node; node = node->Next ())
{
char *string = (char *) node->Data ();
if (string == s || strcmp (string, s) == 0)
{
delete[]string;
delete node;
break; // Done!
}
} // for
}
// Only makes new strings if arg is TRUE
char **wxStringList::ListToArray (const bool new_copies) const
{
char **string_array = new char *[Number ()];
wxNode *node = First ();
int i;
for (i = 0; i < n; i++)
{
char *s = (char *) node->Data ();
if (new_copies)
string_array[i] = copystring (s);
else
string_array[i] = s;
node = node->Next ();
}
return string_array;
}
static int
wx_comparestrings (const void *arg1, const void *arg2)
{
char **s1 = (char **) arg1;
char **s2 = (char **) arg2;
return strcmp (*s1, *s2);
}
// Sort a list of strings - deallocates old nodes, allocates new
void wxStringList::Sort (void)
{
size_t N = n;
char **array = new char *[N];
size_t i = 0;
for (wxNode * node = First (); node; node = node->Next ())
array[i++] = (char *) node->Data ();
qsort (array, N, sizeof (char *), wx_comparestrings);
Clear ();
for (i = 0; i < N; i++)
Append ((wxObject *) (array[i]));
delete[]array;
}
// Checks whether s is a member of the list
bool wxStringList::Member (const char *s) const
{
for (wxNode * node = First (); node; node = node->Next ())
{
const char *s1 = (const char *) node->Data ();
if (s == s1 || strcmp (s, s1) == 0)
return TRUE;
}
return FALSE;
}

611
src/common/log.cpp Normal file
View File

@@ -0,0 +1,611 @@
/////////////////////////////////////////////////////////////////////////////
// Name: log.cpp
// Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
// Author: Vadim Zeitlin
// Modified by:
// Created: 29/01/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "log.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// wxWindows
#ifndef WX_PRECOMP
#include <wx/string.h>
#include <wx/app.h>
#include <wx/generic/msgdlgg.h>
#endif
#include <wx/intl.h>
#include <wx/log.h>
// other standard headers
#include <errno.h>
#include <stdlib.h>
#include <time.h>
// C++ headers
#include <iostream.h>
// _WINDOWS_ is defined when windows.h is included,
// __WINDOWS__ is defined for MS Windows compilation
#if defined(__WINDOWS__) && !defined(_WINDOWS_)
#include <windows.h>
#endif //windows.h
// ----------------------------------------------------------------------------
// non member functions
// ----------------------------------------------------------------------------
// define this to enable wrapping of log messages
//#define LOG_PRETTY_WRAP
#ifdef LOG_PRETTY_WRAP
static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz);
#endif
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// implementation of Log functions
//
// NB: unfortunately we need all these distinct functions, we can't make them
// macros and not all compilers inline vararg functions.
// ----------------------------------------------------------------------------
// log functions can't allocate memory (LogError("out of memory...") should
// work!), so we use a static buffer for all log messages
#define LOG_BUFFER_SIZE (4096)
// static buffer for error messages (@@@ MT-unsafe)
static char s_szBuf[LOG_BUFFER_SIZE];
// generic log function
void wxLogGeneric(wxLog::Level level, wxTString strFormat, ...)
{
if ( wxLog::GetActiveTarget() != NULL ) {
va_list argptr;
va_start(argptr, strFormat);
vsprintf(s_szBuf, strFormat, argptr);
va_end(argptr);
wxLog::OnLog(level, s_szBuf);
}
}
#define IMPLEMENT_LOG_FUNCTION(level) \
void wxLog##level(wxTString strFormat, ...) \
{ \
if ( wxLog::GetActiveTarget() != NULL ) { \
va_list argptr; \
va_start(argptr, strFormat); \
vsprintf(s_szBuf, strFormat, argptr); \
va_end(argptr); \
\
wxLog::OnLog(wxLog::level, s_szBuf); \
} \
}
IMPLEMENT_LOG_FUNCTION(FatalError)
IMPLEMENT_LOG_FUNCTION(Error)
IMPLEMENT_LOG_FUNCTION(Warning)
IMPLEMENT_LOG_FUNCTION(Message)
IMPLEMENT_LOG_FUNCTION(Info)
IMPLEMENT_LOG_FUNCTION(Status)
// debug functions don't use wxTString
#undef IMPLEMENT_LOG_FUNCTION
#define IMPLEMENT_LOG_FUNCTION(level) \
void wxLog##level(const char *szFormat, ...) \
{ \
if ( wxLog::GetActiveTarget() != NULL ) { \
va_list argptr; \
va_start(argptr, szFormat); \
vsprintf(s_szBuf, szFormat, argptr); \
va_end(argptr); \
\
wxLog::OnLog(wxLog::level, s_szBuf); \
} \
}
IMPLEMENT_LOG_FUNCTION(Debug)
IMPLEMENT_LOG_FUNCTION(Trace)
void wxLogVerbose(wxTString strFormat, ...)
{
if ( wxLog::GetVerbose() && wxLog::GetActiveTarget() != NULL ) {
va_list argptr;
va_start(argptr, strFormat);
vsprintf(s_szBuf, strFormat, argptr);
va_end(argptr);
wxLog::OnLog(wxLog::Info, s_szBuf);
}
}
void wxLogSysError(wxTString str, ...)
{
if ( wxLog::GetActiveTarget() != NULL ) {
va_list argptr;
va_start(argptr, str);
vsprintf(s_szBuf, str, argptr);
va_end(argptr);
char szErrMsg[LOG_BUFFER_SIZE / 2];
sprintf(szErrMsg, _(" (error %ld: %s)"), wxSysErrorCode(), wxSysErrorMsg());
strncat(s_szBuf, szErrMsg, WXSIZEOF(s_szBuf) - strlen(s_szBuf));
wxLog::OnLog(wxLog::Error, s_szBuf);
}
}
void WXDLLEXPORT wxLogSysError(long lErrCode, wxTString strFormat, ...)
{
if ( wxLog::GetActiveTarget() != NULL ) {
va_list argptr;
va_start(argptr, strFormat);
vsprintf(s_szBuf, strFormat, argptr);
va_end(argptr);
char szErrMsg[LOG_BUFFER_SIZE / 2];
sprintf(szErrMsg, _(" (error %ld: %s)"), lErrCode, wxSysErrorMsg(lErrCode));
strncat(s_szBuf, szErrMsg, WXSIZEOF(s_szBuf) - strlen(s_szBuf));
wxLog::OnLog(wxLog::Error, s_szBuf);
}
}
// ----------------------------------------------------------------------------
// wxLog class implementation
// ----------------------------------------------------------------------------
wxLog::wxLog()
{
m_bHasMessages = FALSE;
}
wxLog *wxLog::GetActiveTarget()
{
if ( !ms_bInitialized ) {
// prevent infinite recursion if someone calls wxLogXXX() from wxApp
ms_bInitialized = TRUE;
// ask the application to create a log target for us if it exists
if ( wxTheApp != NULL )
ms_pLogger = wxTheApp->CreateLogTarget();
else
ms_pLogger = new wxLogStderr;
// do nothing if it fails - what can we do?
}
return ms_pLogger;
}
wxLog *wxLog::SetActiveTarget(wxLog *pLogger)
{
// flush the old messages before changing
if ( ms_pLogger != NULL )
ms_pLogger->Flush();
ms_bInitialized = TRUE;
wxLog *pOldLogger = ms_pLogger;
ms_pLogger = pLogger;
return pOldLogger;
}
void wxLog::DoLog(Level level, const char *szString)
{
char szBuf[128];
time_t timeNow;
struct tm *ptmNow;
time(&timeNow);
ptmNow = localtime(&timeNow);
strftime(szBuf, WXSIZEOF(szBuf), ms_szTimeFormat, ptmNow);
wxString str = szBuf;
switch ( level ) {
case FatalError:
DoLogString(str << _("Fatal error: ") << szString);
DoLogString(_("Program aborted."));
Flush();
abort();
break;
case Error:
DoLogString(str << _("Error: ") << szString);
break;
case Warning:
DoLogString(str << _("Warning: ") << szString);
break;
case Info:
if ( GetVerbose() )
case Message:
DoLogString(str + szString);
// fall through
case Status:
// nothing to do
break;
case Trace:
case Debug:
#ifdef __DEBUG__
#ifdef __WIN32__
// in addition to normal logging, also send the string to debugger
// (don't prepend "Debug" here: it will go to debug window anyhow)
::OutputDebugString(str + szString + "\n\r");
#endif //Win32
DoLogString(str << (level == Trace ? _("Trace") : _("Debug"))
<< ": " << szString);
#endif
break;
default:
wxFAIL_MSG("unknown log level in wxLog::DoLog");
}
}
void wxLog::DoLogString(const char *WXUNUSED(szString))
{
wxFAIL_MSG("DoLogString must be overrided if it's called.");
}
void wxLog::Flush()
{
// do nothing
}
// ----------------------------------------------------------------------------
// wxLogStderr class implementation
// ----------------------------------------------------------------------------
wxLogStderr::wxLogStderr(FILE *fp)
{
if ( fp == NULL )
m_fp = stderr;
else
m_fp = fp;
}
void wxLogStderr::DoLogString(const char *szString)
{
fputs(szString, m_fp);
fputc('\n', m_fp);
fflush(m_fp);
}
// ----------------------------------------------------------------------------
// wxLogStream implementation
// ----------------------------------------------------------------------------
wxLogStream::wxLogStream(ostream *ostr)
{
if ( ostr == NULL )
m_ostr = &cerr;
else
m_ostr = ostr;
}
void wxLogStream::DoLogString(const char *szString)
{
(*m_ostr) << szString << endl << flush;
}
// ----------------------------------------------------------------------------
// wxLogTextCtrl implementation
// ----------------------------------------------------------------------------
/*
wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl)
: wxLogStream(new ostream(pTextCtrl))
{
}
wxLogTextCtrl::~wxLogTextCtrl()
{
delete m_ostr;
}
*/
// ----------------------------------------------------------------------------
// wxLogGui implementation
// ----------------------------------------------------------------------------
#ifndef WX_TEST_MINIMAL
wxLogGui::wxLogGui()
{
m_bErrors = FALSE;
}
void wxLogGui::Flush()
{
if ( !m_bHasMessages )
return;
// @@@ ugly...
// concatenate all strings (but not too many to not overfill the msg box)
wxString str;
uint nLines = 0,
nMsgCount = m_aMessages.Count();
// start from the most recent message
for ( uint n = nMsgCount; n > 0; n-- ) {
// for Windows strings longer than this value are wrapped (NT 4.0)
const uint nMsgLineWidth = 156;
nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth;
if ( nLines > 25 ) // don't put too many lines in message box
break;
str << m_aMessages[n - 1] << "\n";
}
if ( m_bErrors ) {
wxMessageBox(str, _("Error"), wxOK | wxICON_EXCLAMATION);
}
else {
wxMessageBox(str, _("Information"), wxOK | wxICON_INFORMATION);
}
// no undisplayed messages whatsoever
m_bHasMessages =
m_bErrors = FALSE;
m_aMessages.Empty();
}
// the default behaviour is to discard all informational messages if there
// are any errors/warnings.
void wxLogGui::DoLog(Level level, const char *szString)
{
switch ( level ) {
case Info:
if ( GetVerbose() )
case Message:
if ( !m_bErrors ) {
m_aMessages.Add(szString);
m_bHasMessages = TRUE;
}
break;
case Status:
{
// find the top window and set it's status text if it has any
wxWindow *pWin = wxTheApp->GetTopWindow();
if ( pWin != NULL && pWin->IsKindOf(CLASSINFO(wxFrame)) ) {
wxFrame *pFrame = (wxFrame *)pWin;
pFrame->SetStatusText(szString);
}
}
break;
case Trace:
case Debug:
#ifdef __DEBUG__
#ifdef __WIN32__
OutputDebugString(szString);
OutputDebugString("\n\r");
#else //!WIN32
// send them to stderr
printf(stderr, level == Trace ? "Trace: %s\n"
: "Debug: %s\n", szString);
fflush(stderr);
#endif // WIN32
#endif
break;
case FatalError:
// show this one immediately
wxMessageBox(szString, "Fatal error", wxICON_HAND);
break;
case Error:
case Warning:
// discard earlier informational messages if this is the 1st error
if ( !m_bErrors ) {
m_aMessages.Empty();
m_bHasMessages = TRUE;
m_bErrors = TRUE;
}
m_aMessages.Add(szString);
break;
default:
wxFAIL_MSG("unknown log level in wxLogGui::DoLog");
}
}
#endif //WX_TEST_MINIMAL
// ============================================================================
// Global functions/variables
// ============================================================================
// ----------------------------------------------------------------------------
// static variables
// ----------------------------------------------------------------------------
wxLog *wxLog::ms_pLogger = NULL;
bool wxLog::ms_bInitialized = FALSE;
bool wxLog::ms_bVerbose = FALSE;
const char *wxLog::ms_szTimeFormat = "[%d/%b/%y %H:%M:%S] ";
// ----------------------------------------------------------------------------
// stdout error logging helper
// ----------------------------------------------------------------------------
// helper function: wraps the message and justifies it under given position
// (looks more pretty on the terminal). Also adds newline at the end.
//
// @@ this is now disabled until I find a portable way of determining the
// terminal window size
#ifdef LOG_PRETTY_WRAP
static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz)
{
size_t nMax = 80; // @@@@
size_t nStart = strlen(pszPrefix);
fputs(pszPrefix, f);
size_t n;
while ( *psz != '\0' ) {
for ( n = nStart; (n < nMax) && (*psz != '\0'); n++ )
putc(*psz++, f);
// wrapped?
if ( *psz != '\0' ) {
/*putc('\n', f);*/
for ( n = 0; n < nStart; n++ )
putc(' ', f);
// as we wrapped, squeeze all white space
while ( isspace(*psz) )
psz++;
}
}
putc('\n', f);
}
#endif //LOG_PRETTY_WRAP
// ----------------------------------------------------------------------------
// error code/error message retrieval functions
// ----------------------------------------------------------------------------
// get error code from syste
unsigned long wxSysErrorCode()
{
#ifdef __WINDOWS__
#ifdef __WIN32__
return ::GetLastError();
#else //WIN16
// @@@@ what to do on Windows 3.1?
return 0;
#endif //WIN16/32
#else //Unix
return errno;
#endif //Win/Unix
}
// get error message from system
const char *wxSysErrorMsg(unsigned long nErrCode)
{
if ( nErrCode == 0 )
nErrCode = wxSysErrorCode();
#ifdef __WINDOWS__
#ifdef __WIN32__
static char s_szBuf[LOG_BUFFER_SIZE / 2];
// get error message from system
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, nErrCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
// copy it to our buffer and free memory
strncpy(s_szBuf, (const char *)lpMsgBuf, SIZEOF(s_szBuf) - 1);
s_szBuf[SIZEOF(s_szBuf) - 1] = '\0';
LocalFree(lpMsgBuf);
// returned string is capitalized and ended with '\r\n' - bad
s_szBuf[0] = (char)tolower(s_szBuf[0]);
size_t len = strlen(s_szBuf);
if ( len > 0 ) {
// truncate string
if ( s_szBuf[len - 2] == '\r' )
s_szBuf[len - 2] = '\0';
}
return s_szBuf;
#else
// TODO: Windows 3.1
return NULL;
#endif
#else
return strerror(nErrCode);
#endif
}
// ----------------------------------------------------------------------------
// debug helper
// ----------------------------------------------------------------------------
#ifdef __DEBUG__
// this function is called when an assert fails
void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
{
// this variable can be set to true to suppress "assert failure" messages
static s_bNoAsserts = FALSE;
char szBuf[LOG_BUFFER_SIZE];
sprintf(szBuf, _("Assert failed in file %s at line %d"), szFile, nLine);
if ( szMsg != NULL ) {
strcat(szBuf, ": ");
strcat(szBuf, szMsg);
}
else {
strcat(szBuf, ".");
}
// send it to the normal log destination
wxLogDebug(szBuf);
#ifdef __WINDOWS__
if ( !s_bNoAsserts ) {
strcat(szBuf, _("\nDo you want to stop the program?"
"\nYou can also choose [Cancel] to suppress "
"further warnings."));
switch ( ::MessageBox(NULL, szBuf, _("Debug"),
MB_YESNOCANCEL | MB_ICONINFORMATION) ) {
case IDYES:
DebugBreak();
break;
case IDCANCEL:
s_bNoAsserts = TRUE;
break;
}
}
#else
// @@@@ don't know how to start the debugger under generic Unix
s_bNoAsserts = TRUE; // suppress 'unused var' warning
abort();
#endif
}
#endif //DEBUG

267
src/common/matrix.cpp Normal file
View File

@@ -0,0 +1,267 @@
/////////////////////////////////////////////////////////////////////////////
// Name: matrix.cpp
// Purpose: wxTransformMatrix class
// Author: Chris Breeze, Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "matrix.h"
#endif
// Note: this is intended to be used in wxDC at some point to replace
// the current system of scaling/translation. It is not yet used.
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#endif
#include "wx/matrix.h"
#include <math.h>
const double pi = 3.1415926535;
wxTransformMatrix::wxTransformMatrix(void)
{
m_isIdentity = FALSE;
Identity();
}
wxTransformMatrix::wxTransformMatrix(const wxTransformMatrix& mat)
{
(*this) = mat;
}
double wxTransformMatrix::GetValue(int row, int col) const
{
if (row < 0 || row > 2 || col < 0 || col > 2)
return 0.0;
return m_matrix[row][col];
}
void wxTransformMatrix::SetValue(int row, int col, double value)
{
if (row < 0 || row > 2 || col < 0 || col > 2)
return;
m_matrix[row][col] = value;
}
void wxTransformMatrix::operator = (const wxTransformMatrix& mat)
{
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
m_matrix[i][j] = mat.m_matrix[i][j];
}
}
m_isIdentity = mat.m_isIdentity;
}
bool wxTransformMatrix::operator == (const wxTransformMatrix& mat)
{
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
if (m_matrix[i][j] != mat.m_matrix[i][j])
return FALSE;
}
}
return TRUE;
}
bool wxTransformMatrix::operator != (const wxTransformMatrix& mat)
{
return (! ((*this) == mat));
}
double& wxTransformMatrix::operator()(int row, int col)
{
if (row < 0 || row > 2 || col < 0 || col > 2)
return m_matrix[0][0];
return m_matrix[row][col];
}
double wxTransformMatrix::operator()(int row, int col) const
{
if (row < 0 || row > 2 || col < 0 || col > 2)
return 0.0;
return m_matrix[row][col];
}
// Invert matrix
bool wxTransformMatrix::Invert(void)
{
double inverseMatrix[3][3];
// calculate the adjoint
inverseMatrix[0][0] = wxCalculateDet(m_matrix[1][1],m_matrix[2][1],m_matrix[1][2],m_matrix[2][2]);
inverseMatrix[0][1] = -wxCalculateDet(m_matrix[0][1],m_matrix[2][1],m_matrix[0][2],m_matrix[2][2]);
inverseMatrix[0][2] = wxCalculateDet(m_matrix[0][1],m_matrix[1][1],m_matrix[0][2],m_matrix[1][2]);
inverseMatrix[1][0] = -wxCalculateDet(m_matrix[1][0],m_matrix[2][0],m_matrix[1][2],m_matrix[2][2]);
inverseMatrix[1][1] = wxCalculateDet(m_matrix[0][0],m_matrix[2][0],m_matrix[0][2],m_matrix[2][2]);
inverseMatrix[1][2] = -wxCalculateDet(m_matrix[0][0],m_matrix[1][0],m_matrix[0][2],m_matrix[1][2]);
inverseMatrix[2][0] = wxCalculateDet(m_matrix[1][0],m_matrix[2][0],m_matrix[1][1],m_matrix[2][1]);
inverseMatrix[2][1] = -wxCalculateDet(m_matrix[0][0],m_matrix[2][0],m_matrix[0][1],m_matrix[2][1]);
inverseMatrix[2][2] = wxCalculateDet(m_matrix[0][0],m_matrix[1][0],m_matrix[0][1],m_matrix[1][1]);
// now divide by the determinant
double det = m_matrix[0][0] * inverseMatrix[0][0] + m_matrix[0][1] * inverseMatrix[1][0] + m_matrix[0][2] * inverseMatrix[2][0];
if (det != 0.0)
{
inverseMatrix[0][0] /= det; inverseMatrix[1][0] /= det; inverseMatrix[2][0] /= det;
inverseMatrix[0][1] /= det; inverseMatrix[1][1] /= det; inverseMatrix[2][1] /= det;
inverseMatrix[0][2] /= det; inverseMatrix[1][2] /= det; inverseMatrix[2][2] /= det;
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
m_matrix[i][j] = inverseMatrix[i][j];
}
}
m_isIdentity = IsIdentity1();
return TRUE;
}
else
{
return FALSE;
}
}
// Make into identity matrix
bool wxTransformMatrix::Identity(void)
{
m_matrix[0][0] = m_matrix[1][1] = m_matrix[2][2] = 1.0;
m_matrix[1][0] = m_matrix[2][0] = m_matrix[0][1] = m_matrix[2][1] = m_matrix[0][2] = m_matrix[1][2] = 0.0;
m_isIdentity = TRUE;
return TRUE;
}
// Scale by scale (isotropic scaling i.e. the same in x and y):
// | scale 0 0 |
// matrix' = | 0 scale 0 | x matrix
// | 0 0 scale |
//
bool wxTransformMatrix::Scale(double scale)
{
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
m_matrix[i][j] *= scale;
}
}
m_isIdentity = IsIdentity1();
return TRUE;
}
// Translate by dx, dy:
// | 1 0 dx |
// matrix' = | 0 1 dy | x matrix
// | 0 0 1 |
//
bool wxTransformMatrix::Translate(double dx, double dy)
{
int i;
for (i = 0; i < 3; i++)
m_matrix[i][0] += dx * m_matrix[i][2];
for (i = 0; i < 3; i++)
m_matrix[i][1] += dy * m_matrix[i][2];
m_isIdentity = IsIdentity1();
return TRUE;
}
// Rotate by the given number of degrees:
// | cos sin 0 |
// matrix' = | -sin cos 0 | x matrix
// | 0 0 1 |
//
bool wxTransformMatrix::Rotate(double degrees)
{
double angle = degrees * pi / 180.0;
double s = sin(angle);
double c = cos(angle);
m_matrix[0][0] = c * m_matrix[0][0] + s * m_matrix[0][1];
m_matrix[1][0] = c * m_matrix[1][0] + s * m_matrix[1][1];
m_matrix[2][0] = c * m_matrix[2][0] + s * m_matrix[2][1];
m_matrix[0][2] = c * m_matrix[0][1] - s * m_matrix[0][0];
m_matrix[1][2] = c * m_matrix[1][1] - s * m_matrix[1][0];
m_matrix[2][2] = c * m_matrix[2][1] - s * m_matrix[2][0];
m_isIdentity = IsIdentity1();
return TRUE;
}
// Transform a point from logical to device coordinates
bool wxTransformMatrix::TransformPoint(double x, double y, double& tx, double& ty) const
{
if (IsIdentity())
{
tx = x; ty = y; return TRUE;
}
tx = x * m_matrix[0][0] + y * m_matrix[1][0] + m_matrix[2][0];
ty = x * m_matrix[0][1] + y * m_matrix[1][1] + m_matrix[2][1];
return TRUE;
}
// Transform a point from device to logical coordinates.
// Example of use:
// wxTransformMatrix mat = dc.GetTransformation();
// mat.Invert();
// mat.InverseTransformPoint(x, y, x1, y1);
// OR (shorthand:)
// dc.LogicalToDevice(x, y, x1, y1);
// The latter is slightly less efficient if we're doing several
// conversions, since the matrix is inverted several times.
bool wxTransformMatrix::InverseTransformPoint(double x, double y, double& tx, double& ty) const
{
if (IsIdentity())
{
tx = x; ty = y; return TRUE;
}
double z = (1.0 - m_matrix[0][2] * x - m_matrix[1][2] * y) / m_matrix[2][2];
if (z == 0.0)
{
// z = 0.0000001;
return FALSE;
}
tx = x * m_matrix[0][0] + y * m_matrix[1][0] + z * m_matrix[2][0];
ty = x * m_matrix[0][1] + y * m_matrix[1][1] + z * m_matrix[2][1];
return TRUE;
}

1082
src/common/memory.cpp Normal file

File diff suppressed because it is too large Load Diff

73
src/common/module.cpp Normal file
View File

@@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////
// Name: module.cpp
// Purpose: Modules initialization/destruction
// Author: Wolfram Gloger/adapted by Guilhem Lavaux
// Modified by:
// Created: 04/11/98
// RCS-ID: $Id$
// Copyright: (c) Wolfram Gloger and Guilhem Lavaux
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "module.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/module.h"
IMPLEMENT_CLASS(wxModule, wxObject)
wxList wxModule::m_modules;
void wxModule::RegisterModule(wxModule* module)
{
m_modules.Append(module);
}
// Collect up all module-derived classes, create an instance of each,
// and register them.
bool wxModule::RegisterModules(void)
{
wxClassInfo* classInfo = wxClassInfo::first;
while (classInfo)
{
if ((classInfo != (& (wxModule::classwxModule))) &&
classInfo->IsKindOf(CLASSINFO(wxModule)))
{
wxModule* module = (wxModule*) classInfo->CreateObject();
RegisterModule(module);
}
classInfo = classInfo->next;
}
return TRUE;
}
bool wxModule::InitializeModules(void)
{
// Initialize user-defined modules
for (wxNode *node = m_modules.First(); node; node = node->Next())
{
if (!((wxModule*)(node->Data()))->Init())
return FALSE;
}
return TRUE;
}
void wxModule::CleanUpModules(void)
{
// Cleanup user-defined modules
for(wxNode* node = m_modules.Last(); node; node = node->Previous())
{
((wxModule*)(node->Data()))->Exit();
delete (wxModule*)(node->Data());
}
m_modules.Clear();
}

304
src/common/object.cpp Normal file
View File

@@ -0,0 +1,304 @@
/////////////////////////////////////////////////////////////////////////////
// Name: object.cpp
// Purpose: wxObject implementation
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "object.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/hash.h"
#include <string.h>
#include <assert.h>
#if (DEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
#include "wx/memory.h"
#endif
#if DEBUG || USE_DEBUG_CONTEXT
// for wxObject::Dump
#include <iostream.h>
#endif
#if !USE_SHARED_LIBRARY
wxClassInfo wxObject::classwxObject("wxObject", NULL, NULL, sizeof(wxObject), NULL);
wxClassInfo *wxClassInfo::first = NULL;
#endif
/*
* wxWindows root object.
*/
wxObject::wxObject(void)
{
m_refData = NULL;
}
wxObject::~wxObject(void)
{
UnRef();
}
/*
* Is this object a kind of (a subclass of) 'info'?
* E.g. is wxWindow a kind of wxObject?
* Go from this class to superclass, taking into account
* two possible base classes.
*/
bool wxObject::IsKindOf(wxClassInfo *info)
{
wxClassInfo *thisInfo = GetClassInfo();
if (thisInfo)
return thisInfo->IsKindOf(info);
else
return FALSE;
}
#if DEBUG || USE_DEBUG_CONTEXT
void wxObject::Dump(ostream& str)
{
if (GetClassInfo() && GetClassInfo()->GetClassName())
str << GetClassInfo()->GetClassName();
else
str << "unknown object class";
}
#endif
#if DEBUG && USE_MEMORY_TRACING
#ifdef new
#undef new
#endif
void * wxObject::operator new (size_t size, char * fileName, int lineNum)
{
return wxDebugAlloc(size, fileName, lineNum, TRUE);
}
void wxObject::operator delete (void * buf)
{
wxDebugFree(buf);
}
// Cause problems for VC++ - crashes
#ifndef _MSC_VER
void * wxObject::operator new[] (size_t size, char * fileName, int lineNum)
{
return wxDebugAlloc(size, fileName, lineNum, TRUE, TRUE);
}
void wxObject::operator delete[] (void * buf)
{
wxDebugFree(buf, TRUE);
}
#endif
#endif
/*
* Class info: provides run-time class type information.
*/
#ifdef USE_STORABLE_CLASSES
wxClassInfo::wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn,
wxStorableConstructorFn stoFn )
{
className = cName;
baseClassName1 = baseName1;
baseClassName2 = baseName2;
objectSize = sz;
objectConstructor = fn;
storableConstructor = stoFn;
next = first;
first = this;
baseInfo1 = NULL;
baseInfo2 = NULL;
}
wxObject* wxClassInfo::CreateObject( istream &stream, char *data )
{
if (storableConstructor)
return (wxObject *)(*storableConstructor)( stream, data );
else
return NULL;
}
#else
wxClassInfo::wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn constr)
{
className = cName;
baseClassName1 = baseName1;
baseClassName2 = baseName2;
objectSize = sz;
objectConstructor = constr;
next = first;
first = this;
baseInfo1 = NULL;
baseInfo2 = NULL;
}
#endif
wxObject *wxClassInfo::CreateObject(void)
{
if (objectConstructor)
return (wxObject *)(*objectConstructor)();
else
return NULL;
}
wxClassInfo *wxClassInfo::FindClass(char *c)
{
wxClassInfo *p = first;
while (p)
{
if (p && p->GetClassName() && strcmp(p->GetClassName(), c) == 0)
return p;
p = p->next;
}
return NULL;
}
// Climb upwards through inheritance hierarchy.
// Dual inheritance is catered for.
bool wxClassInfo::IsKindOf(wxClassInfo *info)
{
if (info == NULL)
return FALSE;
// For some reason, when making/using a DLL, static data has to be included
// in both the DLL and the application. This can lead to duplicate
// wxClassInfo objects, so we have to test the name instead of the pointers.
#if WXMAKINGDLL
if (GetClassName() && info->GetClassName() && (strcmp(GetClassName(), info->GetClassName()) == 0))
return TRUE;
#else
if (this == info)
return TRUE;
#endif
if (baseInfo1)
if (baseInfo1->IsKindOf(info))
return TRUE;
if (baseInfo2)
return baseInfo2->IsKindOf(info);
return FALSE;
}
// Set pointers to base class(es) to speed up IsKindOf
void wxClassInfo::InitializeClasses(void)
{
wxHashTable table(wxKEY_STRING);
// Index all class infos by their class name
wxClassInfo *info = first;
while (info)
{
if (info->className)
table.Put(info->className, (wxObject *)info);
info = info->next;
}
// Set base pointers for each wxClassInfo
info = first;
while (info)
{
if (info->GetBaseClassName1())
info->baseInfo1 = (wxClassInfo *)table.Get(info->GetBaseClassName1());
if (info->GetBaseClassName2())
info->baseInfo2 = (wxClassInfo *)table.Get(info->GetBaseClassName2());
info = info->next;
}
}
wxObject *wxCreateDynamicObject(char *name)
{
wxClassInfo *info = wxClassInfo::first;
while (info)
{
if (info->className && strcmp(info->className, name) == 0)
return info->CreateObject();
info = info->next;
}
return NULL;
}
#ifdef USE_STORABLE_CLASSES
wxObject* wxCreateStoredObject( char *name, istream &stream, char *data )
{
wxClassInfo *info = wxClassInfo::first;
while (info)
{
if (info->className && strcmp(info->className, name) == 0)
return info->CreateObject( stream, data );
info = info->next;
}
return NULL;
};
#endif
/*
* wxObject: cloning of objects
*/
void wxObject::Ref(const wxObject& clone)
{
// delete reference to old data
UnRef();
// reference new data
if (clone.m_refData) {
m_refData = clone.m_refData;
++(m_refData->m_count);
}
}
void wxObject::UnRef(void)
{
if (m_refData) {
assert(m_refData->m_count > 0);
--(m_refData->m_count);
if (m_refData->m_count == 0)
delete m_refData;
}
m_refData = NULL;
}
/*
* wxObjectData
*/
wxObjectRefData::wxObjectRefData(void) : m_count(1)
{
}
wxObjectRefData::~wxObjectRefData(void)
{
}

1829
src/common/odbc.cpp Normal file

File diff suppressed because it is too large Load Diff

2577
src/common/postscrp.cpp Normal file

File diff suppressed because it is too large Load Diff

784
src/common/prntbase.cpp Normal file
View File

@@ -0,0 +1,784 @@
/////////////////////////////////////////////////////////////////////////////
// Name: prntbase.cpp
// Purpose: Printing framework base class implementation
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "prntbase.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// #define __GOOD_COMPILER__
#include "wx/defs.h"
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/dc.h"
#include "wx/app.h"
#include "wx/msgdlg.h"
#include "wx/layout.h"
#include "wx/choice.h"
#include "wx/button.h"
#include "wx/settings.h"
#include "wx/dcmemory.h"
#include "wx/stattext.h"
#include "wx/intl.h"
#endif
#include "wx/prntbase.h"
#include "wx/dcprint.h"
#include "wx/printdlg.h"
#include <stdlib.h>
#include <string.h>
#ifdef __WINDOWS__
#include <windows.h>
#include <commdlg.h>
// Clash with Windows header files
#ifdef StartDoc
#undef StartDoc
#endif
#ifndef __WIN32__
#include <print.h>
#endif
#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
#define APIENTRY FAR PASCAL
#endif
#ifdef __WIN32__
#define _EXPORT /**/
#else
#define _EXPORT _export
typedef signed short int SHORT ;
#endif
#if !defined(__WIN32__) // 3.x uses FARPROC for dialogs
#define DLGPROC FARPROC
#endif
LONG APIENTRY _EXPORT wxAbortProc(HDC hPr, int Code);
#endif
// End __WINDOWS__
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxPrinterBase, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxPrintout, wxObject)
IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow)
IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow)
IMPLEMENT_CLASS(wxPreviewFrame, wxFrame)
IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject)
BEGIN_EVENT_TABLE(wxPrintAbortDialog, wxDialog)
EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow)
EVT_PAINT(wxPreviewCanvas::OnPaint)
EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged)
END_EVENT_TABLE()
#endif
/*
* Printer
*/
wxPrinterBase::wxPrinterBase(wxPrintData *data)
{
currentPrintout = NULL;
abortWindow = NULL;
abortIt = FALSE;
if (data)
printData = (*data);
}
wxWindow *wxPrinterBase::abortWindow = NULL;
bool wxPrinterBase::abortIt = FALSE;
wxPrinterBase::~wxPrinterBase(void)
{
}
void wxPrintAbortDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
{
wxPrinterBase::abortIt = TRUE;
wxPrinterBase::abortWindow->Show(FALSE);
wxPrinterBase::abortWindow->Close(TRUE);
wxPrinterBase::abortWindow = NULL;
}
wxWindow *wxPrinterBase::CreateAbortWindow(wxWindow *parent, wxPrintout *WXUNUSED(printout))
{
wxPrintAbortDialog *dialog = new wxPrintAbortDialog(parent, _("Printing"), wxPoint(0, 0), wxSize(400, 400));
(void) new wxStaticText(dialog, -1, _("Please wait..."), wxPoint(5, 5));
wxButton *button = new wxButton(dialog, wxID_CANCEL, _("Cancel"), wxPoint(5, 30));
dialog->Fit();
button->Centre(wxHORIZONTAL);
dialog->Centre();
return dialog;
}
void wxPrinterBase::ReportError(wxWindow *parent, wxPrintout *WXUNUSED(printout), char *message)
{
wxMessageBox(message, "Printing Error", wxOK, parent);
}
/*
* Printout class
*/
wxPrintout::wxPrintout(char *title)
{
printoutTitle = title ? copystring(title) : (char*)NULL;
printoutDC = NULL;
pageWidthMM = 0;
pageHeightMM = 0;
pageWidthPixels = 0;
pageHeightPixels = 0;
PPIScreenX = 0;
PPIScreenY = 0;
PPIPrinterX = 0;
PPIPrinterY = 0;
isPreview = FALSE;
}
wxPrintout::~wxPrintout(void)
{
if (printoutTitle)
delete[] printoutTitle;
}
bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage), int WXUNUSED(endPage))
{
return GetDC()->StartDoc("Printing");
}
void wxPrintout::OnEndDocument(void)
{
GetDC()->EndDoc();
}
void wxPrintout::OnBeginPrinting(void)
{
}
void wxPrintout::OnEndPrinting(void)
{
}
bool wxPrintout::HasPage(int page)
{
return (page == 1);
}
void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toPage)
{
*minPage = 1;
*maxPage = 32000;
*fromPage = 1;
*toPage = 1;
}
/*
* Preview canvas
*/
wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent,
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
wxScrolledWindow(parent, -1, pos, size, style, name)
{
printPreview = preview;
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
SetScrollbars(40, 40, 100, 100);
}
wxPreviewCanvas::~wxPreviewCanvas(void)
{
}
void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
if (printPreview)
{
printPreview->PaintPage(this, dc);
}
}
// Responds to colour changes, and passes event on to children.
void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event)
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
Refresh();
// Propagate the event to the non-top-level children
wxWindow::OnSysColourChanged(event);
}
/*
* Preview control bar
*/
BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel)
EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnClose)
EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint)
EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPrevious)
EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNext)
EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom)
EVT_PAINT(wxPreviewControlBar::OnPaint)
END_EVENT_TABLE()
wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons,
wxWindow *parent, const wxPoint& pos, const wxSize& size,
long style, const wxString& name):
wxPanel(parent, -1, pos, size, style, name)
{
printPreview = preview;
closeButton = NULL;
nextPageButton = NULL;
previousPageButton = NULL;
printButton = NULL;
zoomControl = NULL;
buttonFlags = buttons;
}
wxFont *wxPreviewControlBar::buttonFont = NULL;
wxPreviewControlBar::~wxPreviewControlBar(void)
{
}
void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
int w, h;
GetSize(&w, &h);
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawLine( 0, h-1, w, h-1 );
}
void wxPreviewControlBar::OnClose(wxCommandEvent& WXUNUSED(event))
{
wxPreviewFrame *frame = (wxPreviewFrame *)GetParent();
frame->Close(TRUE);
}
void wxPreviewControlBar::OnPrint(wxCommandEvent& WXUNUSED(event))
{
wxPrintPreviewBase *preview = GetPrintPreview();
preview->Print(TRUE);
}
void wxPreviewControlBar::OnNext(wxCommandEvent& WXUNUSED(event))
{
wxPrintPreviewBase *preview = GetPrintPreview();
if (preview)
{
int currentPage = preview->GetCurrentPage();
if ((preview->GetMaxPage() > 0) &&
(currentPage < preview->GetMaxPage()) &&
preview->GetPrintout()->HasPage(currentPage + 1))
{
preview->SetCurrentPage(currentPage + 1);
}
}
}
void wxPreviewControlBar::OnPrevious(wxCommandEvent& WXUNUSED(event))
{
wxPrintPreviewBase *preview = GetPrintPreview();
if (preview)
{
int currentPage = preview->GetCurrentPage();
if ((preview->GetMinPage() > 0) &&
(currentPage > preview->GetMinPage()) &&
preview->GetPrintout()->HasPage(currentPage - 1))
{
preview->SetCurrentPage(currentPage - 1);
}
}
}
void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event))
{
int zoom = GetZoomControl();
if (GetPrintPreview())
GetPrintPreview()->SetZoom(zoom);
}
void wxPreviewControlBar::CreateButtons(void)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
SetSize(0, 0, 400, 40);
#ifdef __WINDOWS__
int fontSize = 9;
#else
int fontSize = 10;
#endif
if (!buttonFont)
buttonFont = wxTheFontList->FindOrCreateFont(fontSize, wxSWISS, wxNORMAL, wxBOLD);
SetButtonFont(*buttonFont);
int buttonWidth = 65;
int buttonHeight = 24;
int x = 5;
int y = 5;
int gap = 5;
closeButton = new wxButton(this, wxID_PREVIEW_CLOSE, "Close",
wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
x += gap + buttonWidth;
if (buttonFlags & wxPREVIEW_PRINT)
{
printButton = new wxButton(this, wxID_PREVIEW_PRINT, "Print...", wxPoint(x, y),
wxSize(buttonWidth, buttonHeight));
x += gap + buttonWidth;
}
if (buttonFlags & wxPREVIEW_PREVIOUS)
{
previousPageButton = new wxButton(this, wxID_PREVIEW_PREVIOUS, "<<", wxPoint(x, y),
wxSize(buttonWidth, buttonHeight));
x += gap + buttonWidth;
}
if (buttonFlags & wxPREVIEW_NEXT)
{
nextPageButton = new wxButton(this, wxID_PREVIEW_NEXT, ">>",
wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
x += gap + buttonWidth;
}
static wxString choices[] = { "10%", "20%", "25%", "30%", "35%", "40%", "45%", "50%", "55%", "60%",
"65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%", "110%", "120%", "150%", "200%" };
int n = 22;
if (buttonFlags & wxPREVIEW_ZOOM)
{
zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM, wxPoint(x, y),
wxSize(100, -1), n, (wxString *)choices);
SetZoomControl(printPreview->GetZoom());
}
closeButton->SetDefault();
#endif
}
void wxPreviewControlBar::SetZoomControl(int zoom)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
char buf[20];
sprintf(buf, "%d%%", zoom);
if (zoomControl)
zoomControl->SetStringSelection(buf);
#endif
}
int wxPreviewControlBar::GetZoomControl(void)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
char buf[20];
if (zoomControl && zoomControl->GetStringSelection())
{
strcpy(buf, zoomControl->GetStringSelection());
buf[strlen(buf) - 1] = 0;
return (int)atoi(buf);
}
else return 0;
#endif
}
/*
* Preview frame
*/
wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title,
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
wxFrame(parent, -1, title, pos, size, style, name)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
printPreview = preview;
controlBar = NULL;
previewCanvas = NULL;
#endif
}
wxPreviewFrame::~wxPreviewFrame(void)
{
}
bool wxPreviewFrame::OnClose(void)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
MakeModal(FALSE);
// Need to delete the printout and the print preview
wxPrintout *printout = printPreview->GetPrintout();
if (printout)
{
delete printout;
printPreview->SetPrintout(NULL);
printPreview->SetCanvas(NULL);
printPreview->SetFrame(NULL);
}
delete printPreview;
return TRUE;
#endif
}
void wxPreviewFrame::Initialize(void)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
CreateStatusBar();
CreateCanvas();
CreateControlBar();
printPreview->SetCanvas(previewCanvas);
printPreview->SetFrame(this);
// Set layout constraints here
// Control bar constraints
wxLayoutConstraints *c1 = new wxLayoutConstraints;
// int w, h;
// controlBar->GetSize(&w, &h);
int h;
#ifdef __WINDOWS__
h = 40;
#else
h = 60;
#endif
c1->left.SameAs (this, wxLeft);
c1->top.SameAs (this, wxTop);
c1->right.SameAs (this, wxRight);
c1->height.Absolute (h);
controlBar->SetConstraints(c1);
// Canvas constraints
wxLayoutConstraints *c2 = new wxLayoutConstraints;
c2->left.SameAs (this, wxLeft);
c2->top.Below (controlBar);
c2->right.SameAs (this, wxRight);
c2->bottom.SameAs (this, wxBottom);
previewCanvas->SetConstraints(c2);
SetAutoLayout(TRUE);
MakeModal(TRUE);
Layout();
#endif
}
void wxPreviewFrame::CreateCanvas(void)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
previewCanvas = new wxPreviewCanvas(printPreview, this);
#endif
}
void wxPreviewFrame::CreateControlBar(void)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
long buttons = wxPREVIEW_DEFAULT;
if (printPreview->GetPrintoutForPrinting())
buttons |= wxPREVIEW_PRINT;
controlBar = new wxPreviewControlBar(printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40));
controlBar->CreateButtons();
#endif
}
/*
* Print preview
*/
wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
isOk = TRUE;
previewPrintout = printout;
if (previewPrintout)
previewPrintout->SetIsPreview(TRUE);
printPrintout = printoutForPrinting;
if (data)
printData = (*data);
previewCanvas = NULL;
previewFrame = NULL;
previewBitmap = NULL;
currentPage = 1;
currentZoom = 30;
topMargin = 40;
leftMargin = 40;
pageWidth = 0;
pageHeight = 0;
printout->OnPreparePrinting();
// Get some parameters from the printout, if defined
int selFrom, selTo;
printout->GetPageInfo(&minPage, &maxPage, &selFrom, &selTo);
#endif
}
wxPrintPreviewBase::~wxPrintPreviewBase(void)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
if (previewPrintout)
delete previewPrintout;
if (previewBitmap)
delete previewBitmap;
if (printPrintout)
delete printPrintout;
#endif
}
bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
if (currentPage == pageNum)
return TRUE;
currentPage = pageNum;
if (previewBitmap)
{
delete previewBitmap;
previewBitmap = NULL;
}
if (previewCanvas)
{
RenderPage(pageNum);
previewCanvas->Refresh();
}
#endif
return TRUE;
}
bool wxPrintPreviewBase::PaintPage(wxWindow *canvas, wxDC& dc)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
DrawBlankPage(canvas, dc);
if (!previewBitmap)
RenderPage(currentPage);
if (!previewBitmap)
return FALSE;
if (!canvas)
return FALSE;
int canvasWidth, canvasHeight;
canvas->GetSize(&canvasWidth, &canvasHeight);
float zoomScale = (float)((float)currentZoom/(float)100);
float actualWidth = (float)(zoomScale*pageWidth*previewScale);
// float actualHeight = (float)(zoomScale*pageHeight*previewScale);
float x = (float)((canvasWidth - actualWidth)/2.0);
if (x < leftMargin)
x = (float)leftMargin;
float y = (float)topMargin;
wxMemoryDC temp_dc;
temp_dc.SelectObject(*previewBitmap);
dc.Blit((float)x, (float)y, (float)previewBitmap->GetWidth(), (float)previewBitmap->GetHeight(), &temp_dc, (float)0, (float)0);
temp_dc.SelectObject(wxNullBitmap);
#endif
return TRUE;
}
bool wxPrintPreviewBase::RenderPage(int pageNum)
{
int canvasWidth, canvasHeight;
#ifdef __GOOD_COMPILER__ // Robert Roebling
if (!previewCanvas)
{
wxMessageBox("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!",
"Print Preview Failure", wxOK);
return FALSE;
}
previewCanvas->GetSize(&canvasWidth, &canvasHeight);
float zoomScale = (float)((float)currentZoom/(float)100);
float actualWidth = (float)(zoomScale*pageWidth*previewScale);
float actualHeight = (float)(zoomScale*pageHeight*previewScale);
float x = (float)((canvasWidth - actualWidth)/2.0);
if (x < leftMargin)
x = (float)leftMargin;
// float y = topMargin;
if (!previewBitmap)
{
previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight);
if (!previewBitmap || !previewBitmap->Ok())
{
if (previewBitmap)
delete previewBitmap;
wxMessageBox("Sorry, not enough memory to create a preview.", "Print Preview Failure", wxOK);
return FALSE;
}
}
wxMemoryDC memoryDC;
memoryDC.SelectObject(*previewBitmap);
memoryDC.Clear();
previewPrintout->SetDC(&memoryDC);
previewPrintout->SetPageSizePixels(pageWidth, pageHeight);
previewPrintout->OnBeginPrinting();
if (!previewPrintout->OnBeginDocument(printData.GetFromPage(), printData.GetToPage()))
{
wxMessageBox("Could not start document preview.", "Print Preview Failure", wxOK);
memoryDC.SelectObject(wxNullBitmap);
delete previewBitmap;
return FALSE;
}
previewPrintout->OnPrintPage(pageNum);
previewPrintout->OnEndDocument();
previewPrintout->OnEndPrinting();
previewPrintout->SetDC(NULL);
memoryDC.SelectObject(wxNullBitmap);
#endif
char buf[200];
if (maxPage != 0)
sprintf(buf, "Page %d of %d", pageNum, maxPage);
else
sprintf(buf, "Page %d", pageNum);
if (previewFrame)
previewFrame->SetStatusText(buf);
return TRUE;
}
bool wxPrintPreviewBase::DrawBlankPage(wxWindow *canvas, wxDC& dc)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
int canvasWidth, canvasHeight;
canvas->GetSize(&canvasWidth, &canvasHeight);
float zoomScale = (float)((float)currentZoom/(float)100);
float actualWidth = zoomScale*pageWidth*previewScale;
float actualHeight = zoomScale*pageHeight*previewScale;
float x = (float)((canvasWidth - actualWidth)/2.0);
if (x < leftMargin)
x = (float)leftMargin;
float y = (float)topMargin;
// Draw shadow, allowing for 1-pixel border AROUND the actual page
int shadowOffset = 4;
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxBLACK_BRUSH);
dc.DrawRectangle(x-1 + shadowOffset, y-1 + shadowOffset, actualWidth+2, actualHeight+2);
// Draw blank page allowing for 1-pixel border AROUND the actual page
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(x-1, y-1, actualWidth+2, actualHeight+2);
#endif
return TRUE;
}
void wxPrintPreviewBase::SetZoom(int percent)
{
#ifdef __GOOD_COMPILER__ // Robert Roebling
if (currentZoom == percent)
return;
currentZoom = percent;
if (previewBitmap)
{
delete previewBitmap;
previewBitmap = NULL;
}
RenderPage(currentPage);
if (previewCanvas)
{
previewCanvas->Clear();
previewCanvas->Refresh();
}
#endif
}

1210
src/common/string.cpp Normal file

File diff suppressed because it is too large Load Diff

233
src/common/textfile.cpp Normal file
View File

@@ -0,0 +1,233 @@
///////////////////////////////////////////////////////////////////////////////
// Name: textfile.cpp
// Purpose: implementation of wxTextFile class
// Author: Vadim Zeitlin
// Modified by:
// Created: 03.04.98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// headers
// ============================================================================
#ifdef __GNUG__
#pragma implementation "textfile.h"
#endif
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#include <wx/string.h>
#include <wx/intl.h>
#include <wx/file.h>
#include <wx/log.h>
#include <wx/textfile.h>
// ============================================================================
// wxTextFile class implementation
// ============================================================================
// ----------------------------------------------------------------------------
// static variables
// ----------------------------------------------------------------------------
// default type is the native one
const wxTextFile::Type wxTextFile::typeDefault = wxTextFile::
#if defined(__WINDOWS__)
Type_Dos;
#elif defined(__UNIX__)
Type_Unix;
#elif defined(__MAC__)
Type_Mac;
// if you feel brave, remove the next line
#error "wxTextFile: code for Mac files is untested."
#else
Type_None;
#error "wxTextFile: unsupported platform."
#endif
// ----------------------------------------------------------------------------
// ctors & dtor
// ----------------------------------------------------------------------------
wxTextFile::wxTextFile(const wxString& strFile) : m_strFile(strFile)
{
}
wxTextFile::~wxTextFile()
{
// m_file dtor called automatically
}
// ----------------------------------------------------------------------------
// file operations
// ----------------------------------------------------------------------------
bool wxTextFile::Open(const wxString& strFile)
{
m_strFile = strFile;
return Open();
}
bool wxTextFile::Open()
{
// file name must be either given in ctor or in Open(const wxString&)
wxASSERT( !m_strFile.IsEmpty() );
// open file in read-only mode
if ( !m_file.Open(m_strFile) )
return FALSE;
// read file into memory
bool bRet = Read();
m_file.Close();
return bRet;
}
// analyse some lines of the file trying to guess it's type.
// if it fails, it assumes the native type for our platform.
wxTextFile::Type wxTextFile::GuessType() const
{
// file should be opened and we must be in it's beginning
wxASSERT( m_file.IsOpened() && m_file.Tell() == 0 );
// scan the file lines
uint nUnix = 0, // number of '\n's alone
nDos = 0, // number of '\r\n'
nMac = 0; // number of '\r's
// we take MAX_LINES_SCAN in the beginning, middle and the end of file
#define MAX_LINES_SCAN (10)
uint nCount = m_aLines.Count() / 3,
nScan = nCount > 3*MAX_LINES_SCAN ? MAX_LINES_SCAN : nCount / 3;
#define AnalyseLine(n) \
switch ( m_aTypes[n] ) { \
case Type_Unix: nUnix++; break; \
case Type_Dos: nDos++; break; \
case Type_Mac: nMac++; break; \
}
uint n;
for ( n = 0; n < nScan; n++ ) // the beginning
AnalyseLine(n);
for ( n = (nCount - nScan)/2; n < (nCount + nScan)/2; n++ )
AnalyseLine(n);
for ( n = nCount - nScan; n < nCount; n++ )
AnalyseLine(n);
#undef AnalyseLine
// interpret the results (@@ far from being even 50% fool proof)
if ( nDos + nUnix + nMac == 0 ) {
// no newlines at all
wxLogWarning("'%s' is probably a binary file.", m_strFile.c_str());
}
else {
#define GREATER_OF(t1, t2) n##t1 == n##t2 ? typeDefault \
: n##t1 > n##t2 ? Type_##t1 \
: Type_##t2
if ( nDos > nUnix )
return GREATER_OF(Dos, Mac);
else if ( nDos < nUnix )
return GREATER_OF(Unix, Mac);
else {
// nDos == nUnix
return nMac > nDos ? Type_Mac : typeDefault;
}
#undef GREATER_OF
}
return typeDefault;
}
bool wxTextFile::Read()
{
// file should be opened and we must be in it's beginning
wxASSERT( m_file.IsOpened() && m_file.Tell() == 0 );
wxString str;
char ch, chLast = '\0';
while ( !m_file.Eof() ) {
// @@ should really use a buffer for efficiency
if ( m_file.Read(&ch, sizeof(ch)) == ofsInvalid ) {
// read error
m_file.Close();
return FALSE;
}
#ifdef __MAC__
#pragma message("wxTextFile::Read() hasn't been tested with Mac files.")
#endif
switch ( ch ) {
case '\n':
// Dos/Unix line termination
m_aLines.Add(str);
m_aTypes.Add(chLast == '\r' ? Type_Dos : Type_Unix);
str.Empty();
chLast = '\n';
break;
case '\r':
if ( chLast == '\r' ) {
// Mac empty line
m_aLines.Add("");
m_aTypes.Add(Type_Mac);
}
else
chLast = '\r';
break;
default:
if ( chLast == '\r' ) {
// Mac line termination
m_aLines.Add(str);
m_aTypes.Add(Type_Mac);
str = ch;
}
else {
// add to the current line
str += ch;
}
}
}
// anything in the last line?
if ( !str.IsEmpty() ) {
m_aTypes.Add(Type_None); // no line terminator
m_aLines.Add(str);
}
return TRUE;
}
bool wxTextFile::Write(Type typeNew)
{
wxTempFile fileTmp(m_strFile);
if ( !fileTmp.IsOpened() ) {
wxLogError("can't write file '%s' to disk.", m_strFile.c_str());
return FALSE;
}
uint nCount = m_aLines.Count();
for ( uint n = 0; n < nCount; n++ ) {
fileTmp.Write(m_aLines[n] +
GetEOL(typeNew == Type_None ? m_aTypes[n] : typeNew));
}
// replace the old file with this one
return fileTmp.Commit();
}

383
src/common/time.cpp Normal file
View File

@@ -0,0 +1,383 @@
/////////////////////////////////////////////////////////////////////////////
// Name: time.cpp
// Purpose: wxTime class, from NIHCL
// Author: Julian Smart, after K. E. Gorlen
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "time.h"
#endif
/*
Provides an object that represents a Time, stored as the number of
seconds since January 1, 1901, GMT.
*/
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/setup.h"
#if USE_TIMEDATE
#include "wx/time.h"
#include "wx/date.h"
#include "wx/utils.h"
#if USE_IOSTREAMH
#include <iostream.h>
#else
#include <iostream>
#endif
#include <iomanip.h>
#include <string.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxTime, wxObject)
#endif
extern bool wxGetLocalTime(long *timeZone, int *dstObserved);
extern long wxGetCurrentTime(void);
static long TIME_ZONE; /* seconds west of GMT */
static int DST_OBSERVED; /* flags U.S. daylight saving time observed */
static bool wxTimeInitialized = FALSE;
wxTime::tFormat wxTime::Format = wxTime::wx12h;
wxTime::tPrecision wxTime::Precision = wxTime::wxStdMinSec;
static const unsigned long seconds_in_day = 24*60*60L;
static const wxDate refDate(1,1,1901);
// static const wxDate maxDate(49709L); /* ((2**32)-1)/seconds_in_day -1 */
wxTime wxTime::GetLocalTime(const wxDate& date, hourTy h, minuteTy m, secondTy s)
/*
Return a local wxTime for the specified Standard Time date, hour, minute,
and second.
*/
{
if (!wxTimeInitialized)
{
wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED);
wxTimeInitialized = TRUE;
}
/*
if (!date.IsBetween(refDate,maxDate))
setError(NIHCL_DATERANGE,DEFAULT,
date.dayOfMonth(),date.nameOfMonth(),date.year());
*/
// The following line causes an error in GCC 2.1
// long daysBetween = date-refDate;
// ... but this seems to get round it.
wxDate tmp1(date);
wxDate tmp2(refDate);
long daysBetween = tmp1 - tmp2;
return wxTime(seconds_in_day*daysBetween + 60*60L*h + 60*m + s);
}
wxTime::wxTime()
/*
Construct a wxTime for this instant.
*/
{
if (!wxTimeInitialized)
{
wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED);
wxTimeInitialized = TRUE;
}
sec = wxGetCurrentTime();
sec += 2177452800L; /* seconds from 1/1/01 to 1/1/70 */
}
wxTime::wxTime(hourTy h, minuteTy m, secondTy s, bool dst)
/*
Construct a wxTime for today at the specified (local) hour, minute, and
second.
*/
{
if (!wxTimeInitialized)
{
wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED);
wxTimeInitialized = TRUE;
}
sec = wxTime(wxDate(),h,m,s,dst).sec;
}
wxTime::wxTime(const wxDate& date, hourTy h, minuteTy m, secondTy s, bool dst)
/*
Construct a wxTime for the specified (local) Date, hour, minute, and
second.
*/
{
if (!wxTimeInitialized)
{
wxGetLocalTime(&TIME_ZONE, &DST_OBSERVED);
wxTimeInitialized = TRUE;
}
sec = GetLocalTime(date,h,m,s).sec-3600;
if (IsDST())
{
sec += 3600;
if (IsDST() || dst) sec -= 3600;
}
else
{
sec += 3600;
/*
if (IsDST()) setError(NIHCL_BADTIME,DEFAULT,
date.dayOfMonth(),date.nameOfMonth(),date.year(),
h,m,s,(dst?"DST":""));
*/
}
sec += TIME_ZONE; // adjust to GMT
}
wxTime::operator wxDate() const
/*
Convert a wxTime to a local wxDate
*/
{
// return wxDate((int)(GetLocalTime().sec/seconds_in_day)); 4.2 cc bug
long daycount = (long)(GetLocalTime().sec/seconds_in_day);
wxDate date(1,1,1901);
date += daycount;
return date;
}
bool wxTime::IsBetween(const wxTime& a, const wxTime& b) const
{
return *this >= a && *this <= b;
}
hourTy wxTime::GetHour() const
/*
Return the hour of this wxTime in local time; i.e., adjust for
time zone and Daylight Savings Time.
*/
{
return GetLocalTime().GetHourGMT();
}
hourTy wxTime::GetHourGMT() const
/*
Return the hour of this Time in GMT.
*/
{
return (hourTy)((sec % 86400) / 3600);
}
wxTime wxTime::GetBeginDST(unsigned year)
/*
Return the local Standard Time at which Daylight Savings Time
begins in the specified year.
*/
{
// Previous Sunday
wxTime DSTtime(GetLocalTime(wxDate(3,31,year).Previous(1)+7,2));
if (year<=1986) {
// Previous Sunday
DSTtime = GetLocalTime(wxDate(4,30,year).Previous(1),2);
if (year==1974) DSTtime = GetLocalTime(wxDate(1,6,1974),2);
if (year==1975) DSTtime = GetLocalTime(wxDate(2,23,1975),2);
}
return DSTtime;
}
wxTime wxTime::GetEndDST(unsigned year)
/*
Return the local Standard Time at which Daylight Savings Time
ends in the specified year.
*/
{
wxTime STDtime(GetLocalTime(wxDate(10,31,year).Previous(1),2-1));
return STDtime;
}
bool wxTime::IsDST() const
/*
Return TRUE if this local Standard Time should be adjusted
for Daylight Savings Time.
*/
{
long daycount = (long)(sec/seconds_in_day);
// At this point, daycount is the number of days from 1/1/1901.
// Need to convert to julian date (which starts at 1/1/4713 B.C.)
wxDate date(1,1,1901);
date += daycount;
unsigned year = date.GetYear();
if (DST_OBSERVED)
{
if (*this >= GetBeginDST(year))
if (*this < GetEndDST(year)) return TRUE;
}
return FALSE;
}
wxTime wxTime::GetLocalTime() const
/*
Adjusts this GM Time for local time zone and Daylight Savings Time.
*/
{
wxTime local_time(sec-TIME_ZONE);
if (local_time.IsDST()) local_time.sec += 3600;
return local_time;
}
minuteTy wxTime::GetMinute() const
/*
Return the minute of this wxTime in local time; i.e., adjust
for time zone and Daylight Savings Time.
*/
{
return GetLocalTime().GetMinuteGMT();
}
minuteTy wxTime::GetMinuteGMT() const
/*
Return the minute of this wxTime in GMT.
*/
{
return (minuteTy)(((sec % 86400) % 3600) / 60);
}
secondTy wxTime::GetSecond() const
/*
Return the second of this wxTime.
*/
{
return (secondTy)(((sec % 86400) % 3600) % 60);
}
wxTime wxTime::Max(const wxTime& t) const
{
if (t < *this) return *this;
return t;
}
wxTime wxTime::Min(const wxTime& t) const
{
if (t > *this) return *this;
return t;
}
wxTime::operator char *(void)
{
return FormatTime();
}
void wxTime::SetFormat(const wxTime::tFormat lFormat,
const wxTime::tPrecision lPrecision) {
wxTime::Format = lFormat;
wxTime::Precision = lPrecision;
}
char *wxTime::FormatTime() const {
static char timeBuf[30];
unsigned hh(GetHour());
switch (Format) {
case wx12h:
hh -= 12;
break;
case wx24h:
break;
}
switch (Precision) {
case wxStdMinSec:
sprintf(timeBuf,"%2d:%02d:%02d",hh,GetMinute(),GetSecond());
break;
case wxStdMin:
sprintf(timeBuf,"%2d:%02d",hh,GetMinute());
break;
}
if (Format == wx12h)
if (GetHour() <= 12)
strcat(timeBuf,"am");
else
strcat(timeBuf,"pm");
return timeBuf;
}
/*
int wxTime::compare(const Object& ob) const
{
assertArgSpecies(ob,classDesc,"compare");
register clockTy t = castdown(ob).sec;
if (sec < t) return -1;
if (sec > t) return 1;
return 0;
}
void wxTime::deepenShallowCopy() {}
unsigned wxTime::hash() const { return sec; }
bool wxTime::isEqual(const Object& ob) const
{
return ob.isSpecies(classDesc) && *this==castdown(ob);
}
const Class* wxTime::species() const { return &classDesc; }
void wxTime::printOn(ostream& strm) const
{
register unsigned hh = GetHour();
wxDate(*this).printOn(strm);
strm << ' ' << ((hh <= 12) ? hh : hh-12) << ':'
<< setfill('0') << setw(2) << GetMinute() << ':'
<< setfill('0') << setw(2) << GetSecond() << ' ';
if (hh < 12) strm << "am";
else strm << "pm";
}
wxTime::wxTime(OIOin& strm)
: BASE(strm)
{
unsigned long usec;
strm >> sec >> usec;
}
void wxTime::storer(OIOout& strm) const
{
BASE::storer(strm);
strm << sec << 0l;
}
wxTime::wxTime(OIOifd& fd)
: BASE(fd)
{
unsigned long usec;
fd >> sec >> usec;
}
void wxTime::storer(OIOofd& fd) const
{
BASE::storer(fd);
fd << sec << 0l;
}
*/
#endif

207
src/common/timercmn.cpp Normal file
View File

@@ -0,0 +1,207 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timercmn.cpp
// Purpose: Common timer implementation
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
//#pragma implementation "timercmn.h"
#pragma implementation
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include "wx/list.h"
#endif
#include "wx/timer.h"
#ifdef __SVR4__
#define __SYSV__
#endif
#include <time.h>
#include <sys/types.h>
#if (!defined(__SC__) && !defined(__SGI__) && !defined(__GNUWIN32__)) || defined(__MINGW32__)
#include <sys/timeb.h>
#endif
#if defined(__linux__) || defined(__SVR4__) || defined(__SYSV__) || defined(__SGI__) || defined(__ALPHA__) || defined(__GNUWIN32__)
#include <sys/time.h>
#endif
#ifdef __MINGW32__
#include "windows.h"
#endif
#if defined(__SUN__) || defined(__OSF__)
// At least on Sun, ftime is undeclared.
// Need to be verified on other platforms.
extern "C" int ftime(struct timeb *tp);
// extern "C" time_t time(time_t);
// #include <sys/timeb.h>
#if defined(__SVR4__) && !defined(__ALPHA__)
// ditto for gettimeofday on Solaris 2.x.
extern "C" int gettimeofday(struct timeval *tp, void *);
#endif
#endif
/*
* Timer functions
*
*/
long wxStartTime = 0;
void wxStartTimer(void)
{
#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
struct timeval tp;
#ifdef __SYSV__
gettimeofday(&tp, (struct timezone *)NULL);
#else
gettimeofday(&tp);
#endif
wxStartTime = 1000*tp.tv_sec + tp.tv_usec/1000;
#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
time_t t0;
struct tm *tp;
time(&t0);
tp = localtime(&t0);
wxStartTime = 1000*(60*(60*tp->tm_hour+tp->tm_min)+tp->tm_sec);
#else
struct timeb tp;
ftime(&tp);
wxStartTime = 1000*tp.time + tp.millitm;
#endif
}
// Returns elapsed time in milliseconds
long wxGetElapsedTime(bool resetTimer)
{
#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
struct timeval tp;
#ifdef __SYSV__
gettimeofday(&tp, (struct timezone *)NULL);
#else
gettimeofday(&tp);
#endif
long oldTime = wxStartTime;
long newTime = 1000*tp.tv_sec + tp.tv_usec / 1000;
if (resetTimer)
wxStartTime = newTime;
#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
time_t t0;
struct tm *tp;
time(&t0);
tp = localtime(&t0);
long oldTime = wxStartTime;
long newTime = 1000*(60*(60*tp->tm_hour+tp->tm_min)+tp->tm_sec);
if (resetTimer)
wxStartTime = newTime;
#else
struct timeb tp;
ftime(&tp);
long oldTime = wxStartTime;
long newTime = 1000*tp.time + tp.millitm;
if (resetTimer)
wxStartTime = newTime;
#endif
return newTime - oldTime;
}
// EXPERIMENTAL: comment this out if it doesn't compile.
#ifndef __VMS__
bool wxGetLocalTime(long *timeZone, int *dstObserved)
{
#if defined(__MINGW32__) && defined(__EGCS__)
time_t t0;
struct tm *tp;
time(&t0);
tp = localtime(&t0);
*timeZone = timezone; // tp->tm_gmtoff; // ???
*dstObserved = tp->tm_isdst;
#elif defined(__MINGW32__)
time_t t0;
struct tm *tp;
time(&t0);
tp = localtime(&t0);
timeb tz;
ftime(& tz);
*timeZone = tz._timezone;
*dstObserved = tp->tm_isdst;
#else
#if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WINDOWS__)) && !defined(__GNUWIN32__))
#ifdef __BORLANDC__
/* Borland uses underscores */
*timeZone = _timezone;
*dstObserved = _daylight;
#else
*timeZone = timezone;
*dstObserved = daylight;
#endif
#elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
struct timeval tp;
#if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
struct timezone tz;
gettimeofday(&tp, &tz);
*timeZone = 60*(tz.tz_minuteswest);
*dstObserved = tz.tz_dsttime;
#else
time_t t0;
struct tm *tp;
time(&t0);
tp = localtime(&t0);
*timeZone = tp->tm_gmtoff; // ???
*dstObserved = tp->tm_isdst;
#endif
#else
// #error wxGetLocalTime not implemented.
struct timeval tp;
struct timezone tz;
gettimeofday(&tp, &tz);
*timeZone = 60*(tz.tz_minuteswest);
*dstObserved = tz.tz_dsttime;
#endif
#endif
// __MINGW32__
return TRUE;
}
#endif
// Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
long wxGetCurrentTime(void)
{
#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
struct timeval tp;
#ifdef __SYSV__
gettimeofday(&tp, (struct timezone *)NULL);
#else
gettimeofday(&tp);
#endif
return tp.tv_sec;
#else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))
return time(0);
#endif
/*
#else
struct timeb tp;
ftime(&tp);
return tp.time;
#endif
*/
}

742
src/common/utilscmn.cpp Normal file
View File

@@ -0,0 +1,742 @@
/////////////////////////////////////////////////////////////////////////////
// Name: utilscmn.cpp
// Purpose: Miscellaneous utility functions and classes
// Author: Julian Smart
// Modified by:
// Created: 29/01/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Julian Smart
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "utils.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include "wx/utils.h"
#include "wx/window.h"
#include "wx/menu.h"
#include "wx/frame.h"
#endif
#if USE_IOSTREAMH
#include <iostream.h>
#else
#include <iostream>
#endif
#include <fstream.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(__WATCOMC__)
#if !(defined(_MSC_VER) && (_MSC_VER > 800))
#include <errno.h>
#endif
#endif
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
// Pattern matching code.
// Yes, this path is deliberate (for Borland compilation)
#ifdef wx_mac /* MATTHEW: [5] Mac doesn't like paths with "/" */
#include "glob.inc"
#else
#include "../common/glob.inc"
#endif
#ifdef __WINDOWS__
#include "windows.h"
#endif
#define _MAXPATHLEN 500
extern char *wxBuffer;
#ifdef __VMS__
// we have no strI functions under VMS, therefore I have implemented
// an inefficient but portable version: convert copies of strings to lowercase
// and then use the normal comparison
static void myLowerString(char *s)
{
while(*s){
if(isalpha(*s)) *s = (char)tolower(*s);
s++;
}
}
int strcasecmp(const char *str_1, const char *str_2)
{
char *temp1 = new char[strlen(str_1)+1];
char *temp2 = new char[strlen(str_2)+1];
strcpy(temp1,str_1);
strcpy(temp2,str_2);
myLowerString(temp1);
myLowerString(temp2);
int result = strcmp(temp1,temp2);
delete[] temp1;
delete[] temp2;
return(result);
}
int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
{
char *temp1 = new char[strlen(str_1)+1];
char *temp2 = new char[strlen(str_2)+1];
strcpy(temp1,str_1);
strcpy(temp2,str_2);
myLowerString(temp1);
myLowerString(temp2);
int result = strncmp(temp1,temp2,maxchar);
delete[] temp1;
delete[] temp2;
return(result);
}
#endif
#ifdef __WINDOWS__
#ifndef __GNUWIN32__
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif
#ifdef _MSC_VER
#pragma warning (disable : 4245)
#endif
#ifdef _MSC_VER
#pragma warning (default : 4245)
#endif
#else
// This declaration is missing in SunOS!
// (Yes, I know it is NOT ANSI-C but its in BSD libc)
#if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
extern "C"
{
int strcasecmp (const char *, const char *);
int strncasecmp (const char *, const char *, size_t);
}
#endif
#endif /* __WINDOWS__ */
char *
copystring (const char *s)
{
if (s == NULL) s = "";
size_t len = strlen (s) + 1;
char *news = new char[len];
memcpy (news, s, len); // Should be the fastest
return news;
}
// Id generation
static long wxCurrentId = 100;
long
wxNewId (void)
{
return wxCurrentId++;
}
long
wxGetCurrentId(void) { return wxCurrentId; }
void
wxRegisterId (long id)
{
if (id >= wxCurrentId)
wxCurrentId = id + 1;
}
void
StringToFloat (char *s, float *number)
{
if (s && *s && number)
*number = (float) strtod (s, NULL);
}
void
StringToDouble (char *s, double *number)
{
if (s && *s && number)
*number = strtod (s, NULL);
}
char *
FloatToString (float number, const char *fmt)
{
static char buf[256];
// sprintf (buf, "%.2f", number);
sprintf (buf, fmt, number);
return buf;
}
char *
DoubleToString (double number, const char *fmt)
{
static char buf[256];
sprintf (buf, fmt, number);
return buf;
}
void
StringToInt (char *s, int *number)
{
if (s && *s && number)
*number = (int) strtol (s, NULL, 10);
}
void
StringToLong (char *s, long *number)
{
if (s && *s && number)
*number = strtol (s, NULL, 10);
}
char *
IntToString (int number)
{
static char buf[20];
sprintf (buf, "%d", number);
return buf;
}
char *
LongToString (long number)
{
static char buf[20];
sprintf (buf, "%ld", number);
return buf;
}
// Array used in DecToHex conversion routine.
static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F' };
// Convert 2-digit hex number to decimal
int wxHexToDec(char *buf)
{
int firstDigit, secondDigit;
if (buf[0] >= 'A')
firstDigit = buf[0] - 'A' + 10;
else
firstDigit = buf[0] - '0';
if (buf[1] >= 'A')
secondDigit = buf[1] - 'A' + 10;
else
secondDigit = buf[1] - '0';
return firstDigit * 16 + secondDigit;
}
// Convert decimal integer to 2-character hex string
void wxDecToHex(int dec, char *buf)
{
int firstDigit = (int)(dec/16.0);
int secondDigit = (int)(dec - (firstDigit*16.0));
buf[0] = hexArray[firstDigit];
buf[1] = hexArray[secondDigit];
buf[2] = 0;
}
// Match a string INDEPENDENT OF CASE
bool
StringMatch (char *str1, char *str2, bool subString, bool exact)
{
if (str1 == NULL || str2 == NULL)
return FALSE;
if (str1 == str2)
return TRUE;
if (subString)
{
int len1 = strlen (str1);
int len2 = strlen (str2);
int i;
// Search for str1 in str2
// Slow .... but acceptable for short strings
for (i = 0; i <= len2 - len1; i++)
{
if (strncasecmp (str1, str2 + i, len1) == 0)
return TRUE;
}
}
else if (exact)
{
if (strcasecmp (str1, str2) == 0)
return TRUE;
}
else
{
int len1 = strlen (str1);
int len2 = strlen (str2);
if (strncasecmp (str1, str2, wxMin (len1, len2)) == 0)
return TRUE;
}
return FALSE;
}
// Return the current date/time
// [volatile]
wxString wxNow( void )
{
time_t now = time(NULL);
char *date = ctime(&now);
date[24] = '\0';
return wxString(date);
}
/* Get Full RFC822 style email address */
bool
wxGetEmailAddress (char *address, int maxSize)
{
char host[65];
char user[65];
if (wxGetHostName(host, 64) == FALSE)
return FALSE;
if (wxGetUserId(user, 64) == FALSE)
return FALSE;
char tmp[130];
strcpy(tmp, user);
strcat(tmp, "@");
strcat(tmp, host);
strncpy(address, tmp, maxSize - 1);
address[maxSize-1] = '\0';
return TRUE;
}
/*
* Strip out any menu codes
*/
char *wxStripMenuCodes (char *in, char *out)
{
if (!in)
return NULL;
if (!out)
out = copystring(in);
char *tmpOut = out;
while (*in)
{
if (*in == '&')
{
// Check && -> &, &x -> x
if (*++in == '&')
*out++ = *in++;
}
else if (*in == '\t')
{
// Remove all stuff after \t in X mode, and let the stuff as is
// in Windows mode.
// Accelerators are handled in wx_item.cc for Motif, and are not
// YET supported in XView
break;
}
else
*out++ = *in++;
} // while
*out = '\0';
return tmpOut;
}
/*
* Window search functions
*
*/
/*
* If parent is non-NULL, look through children for a label or title
* matching the specified string. If NULL, look through all top-level windows.
*
*/
static wxWindow *wxFindWindowByLabel1 (const wxString& title, wxWindow * parent);
wxWindow *
wxFindWindowByLabel (const wxString& title, wxWindow * parent)
{
if (parent)
{
return wxFindWindowByLabel1 (title, parent);
}
else
{
for (wxNode * node = wxTopLevelWindows.First (); node; node = node->Next ())
{
wxWindow *win = (wxWindow *) node->Data ();
wxWindow *retwin = wxFindWindowByLabel1 (title, win);
if (retwin)
return retwin;
} // for()
}
return NULL;
}
// Recursive
static wxWindow *
wxFindWindowByLabel1 (const wxString& title, wxWindow * parent)
{
if (parent)
{
if (parent->GetLabel() == title)
return parent;
}
if (parent)
{
for (wxNode * node = parent->GetChildren()->First (); node; node = node->Next ())
{
wxWindow *win = (wxWindow *) node->Data ();
wxWindow *retwin = wxFindWindowByLabel1 (title, win);
if (retwin)
return retwin;
} // for()
}
return NULL; // Not found
}
/*
* If parent is non-NULL, look through children for a name
* matching the specified string. If NULL, look through all top-level windows.
*
*/
static wxWindow *wxFindWindowByName1 (const wxString& title, wxWindow * parent);
wxWindow *
wxFindWindowByName (const wxString& title, wxWindow * parent)
{
if (parent)
{
return wxFindWindowByName1 (title, parent);
}
else
{
for (wxNode * node = wxTopLevelWindows.First (); node; node = node->Next ())
{
wxWindow *win = (wxWindow *) node->Data ();
wxWindow *retwin = wxFindWindowByName1 (title, win);
if (retwin)
return retwin;
} // for()
}
// Failed? Try by label instead.
return wxFindWindowByLabel(title, parent);
}
// Recursive
static wxWindow *
wxFindWindowByName1 (const wxString& title, wxWindow * parent)
{
if (parent)
{
if ( parent->GetName() == title )
return parent;
}
if (parent)
{
for (wxNode * node = parent->GetChildren()->First (); node; node = node->Next ())
{
wxWindow *win = (wxWindow *) node->Data ();
wxWindow *retwin = wxFindWindowByName1 (title, win);
if (retwin)
return retwin;
} // for()
}
return NULL; // Not found
}
// Returns menu item id or -1 if none.
int
wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& itemString)
{
wxMenuBar *menuBar = frame->GetMenuBar ();
if (!menuBar)
return -1;
return menuBar->FindMenuItem (menuString, itemString);
}
/*
* wxDebugStreamBuf
*/
#if !defined(_WINDLL)
wxDebugStreamBuf::wxDebugStreamBuf(void)
{
if (allocate()) setp(base(),ebuf());
}
int wxDebugStreamBuf::overflow(int WXUNUSED(i))
{
int len = pptr() - pbase();
char *txt = new char[len+1];
strncpy(txt, pbase(), len);
txt[len] = '\0';
#ifdef __WINDOWS__
OutputDebugString((LPCSTR)txt);
#else
fprintf(stderr, txt);
#endif
setp(pbase(), epptr());
delete[] txt;
return EOF;
}
int wxDebugStreamBuf::sync(void)
{
int len = pptr() - pbase();
char *txt = new char[len+1];
strncpy(txt, pbase(), len);
txt[len] = '\0';
#ifdef __WINDOWS__
OutputDebugString((LPCSTR)txt);
#else
fprintf(stderr, txt);
#endif
setp(pbase(), epptr());
delete[] txt;
return 0;
}
#endif
/*
On Fri, 21 Jul 1995, Paul Craven wrote:
> Is there a way to find the path of running program's executable? I can get
> my home directory, and the current directory, but I don't know how to get the
> executable directory.
>
The code below (warty as it is), does what you want on most Unix,
DOS, and Mac platforms (it's from the ALS Prolog main).
|| Ken Bowen Applied Logic Systems, Inc. PO Box 180,
||==== Voice: +1 (617)965-9191 Newton Centre,
|| FAX: +1 (617)965-1636 MA 02159 USA
Email: ken@als.com WWW: http://www.als.com
------------------------------------------------------------------------
*/
// This code is commented out but it may be integrated with wxWin at
// a later date, after testing. Thanks Ken!
#if 0
/*--------------------------------------------------------------------*
| whereami is given a filename f in the form: whereami(argv[0])
| It returns the directory in which the executable file (containing
| this code [main.c] ) may be found. A dot will be returned to indicate
| the current directory.
*--------------------------------------------------------------------*/
static void
whereami(name)
char *name;
{
register char *cutoff = NULL; /* stifle -Wall */
register char *s;
register char *t;
int cc;
char ebuf[4096];
/*
* See if the file is accessible either through the current directory
* or through an absolute path.
*/
if (access(name, R_OK) == 0) {
/*-------------------------------------------------------------*
* The file was accessible without any other work. But the current
* working directory might change on us, so if it was accessible
* through the cwd, then we should get it for later accesses.
*-------------------------------------------------------------*/
t = imagedir;
if (!absolute_pathname(name)) {
#if defined(DOS) || defined(__WIN32__)
int drive;
char *newrbuf;
newrbuf = imagedir;
#ifndef __DJGPP__
if (*(name + 1) == ':') {
if (*name >= 'a' && *name <= 'z')
drive = (int) (*name - 'a' + 1);
else
drive = (int) (*name - 'A' + 1);
*newrbuf++ = *name;
*newrbuf++ = *(name + 1);
*newrbuf++ = DIR_SEPARATOR;
}
else {
drive = 0;
*newrbuf++ = DIR_SEPARATOR;
}
if (getcwd(newrbuf, drive) == 0) { /* } */
#else
if (getcwd(newrbuf, 1024) == 0) { /* } */
#endif
#else /* DOS */
#ifdef HAVE_GETWD
if (getwd(imagedir) == 0) { /* } */
#else /* !HAVE_GETWD */
if (getcwd(imagedir, 1024) == 0) {
#endif /* !HAVE_GETWD */
#endif /* DOS */
fatal_error(FE_GETCWD, 0);
}
for (; *t; t++) /* Set t to end of buffer */
;
if (*(t - 1) == DIR_SEPARATOR) /* leave slash if already
* last char
*/
cutoff = t - 1;
else {
cutoff = t; /* otherwise put one in */
*t++ = DIR_SEPARATOR;
}
}
#if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
else
(*t++ = DIR_SEPARATOR);
#endif
/*-------------------------------------------------------------*
* Copy the rest of the string and set the cutoff if it was not
* already set. If the first character of name is a slash, cutoff
* is not presently set but will be on the first iteration of the
* loop below.
*-------------------------------------------------------------*/
for ((*name == DIR_SEPARATOR ? (s = name+1) : (s = name));;) {
if (*s == DIR_SEPARATOR)
cutoff = t;
if (!(*t++ = *s++))
break;
}
}
else {
/*-------------------------------------------------------------*
* Get the path list from the environment. If the path list is
* inaccessible for any reason, leave with fatal error.
*-------------------------------------------------------------*/
#ifdef __MAC__
if ((s = getenv("Commands")) == (char *) 0)
#else
if ((s = getenv("PATH")) == (char *) 0)
#endif
fatal_error(FE_PATH, 0);
/*
* Copy path list into ebuf and set the source pointer to the
* beginning of this buffer.
*/
strcpy(ebuf, s);
s = ebuf;
for (;;) {
t = imagedir;
while (*s && *s != PATH_SEPARATOR)
*t++ = *s++;
if (t > imagedir && *(t - 1) == DIR_SEPARATOR)
; /* do nothing -- slash already is in place */
else
*t++ = DIR_SEPARATOR; /* put in the slash */
cutoff = t - 1; /* set cutoff */
strcpy(t, name);
if (access(imagedir, R_OK) == 0)
break;
if (*s)
s++; /* advance source pointer */
else
fatal_error(FE_INFND, 0);
}
}
/*-------------------------------------------------------------*
| At this point the full pathname should exist in imagedir and
| cutoff should be set to the final slash. We must now determine
| whether the file name is a symbolic link or not and chase it down
| if it is. Note that we reuse ebuf for getting the link.
*-------------------------------------------------------------*/
#ifdef HAVE_SYMLINK
while ((cc = readlink(imagedir, ebuf, 512)) != -1) {
ebuf[cc] = 0;
s = ebuf;
if (*s == DIR_SEPARATOR) {
t = imagedir;
}
else {
t = cutoff + 1;
}
for (;;) {
if (*s == DIR_SEPARATOR)
cutoff = t; /* mark the last slash seen */
if (!(*t++ = *s++)) /* copy the character */
break;
}
}
#endif /* HAVE_SYMLINK */
strcpy(imagename, cutoff + 1); /* keep the image name */
*(cutoff + 1) = 0; /* chop off the filename part */
}
#endif

44
src/common/validate.cpp Normal file
View File

@@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////
// Name: validate.cpp
// Purpose: wxValidator
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "validate.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx.h"
#endif
#include "wx/validate.h"
const wxValidator wxDefaultValidator;
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxValidator, wxEvtHandler)
#endif
wxValidator::wxValidator(void)
{
m_validatorWindow = NULL;
}
wxValidator::~wxValidator()
{
}

293
src/common/valtext.cpp Normal file
View File

@@ -0,0 +1,293 @@
/////////////////////////////////////////////////////////////////////////////
// Name: valtext.cpp
// Purpose: wxTextValidator
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "valtext.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/textctrl.h"
#include "wx/utils.h"
#include "wx/msgbxdlg.h"
#endif
#include "wx/valtext.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxTextValidator, wxValidator)
BEGIN_EVENT_TABLE(wxTextValidator, wxValidator)
EVT_CHAR(wxTextValidator::OnChar)
END_EVENT_TABLE()
#endif
wxTextValidator::wxTextValidator(const long style, wxString *val)
{
m_validatorStyle = style ;
m_stringValue = val ;
/*
m_refData = new wxVTextRefData;
M_VTEXTDATA->m_validatorStyle = style ;
M_VTEXTDATA->m_stringValue = val ;
*/
}
wxTextValidator::wxTextValidator(const wxTextValidator& val)
{
Copy(val);
}
bool wxTextValidator::Copy(const wxTextValidator& val)
{
wxValidator::Copy(val);
m_validatorStyle = val.m_validatorStyle ;
m_stringValue = val.m_stringValue ;
wxNode *node = val.m_includeList.First() ;
while ( node )
{
char *s = (char *)node->Data();
m_includeList.Add(s);
node = node->Next();
}
node = val.m_excludeList.First() ;
while ( node )
{
char *s = (char *)node->Data();
m_excludeList.Add(s);
node = node->Next();
}
return TRUE;
}
wxTextValidator::~wxTextValidator()
{
}
static bool wxIsAlpha(const wxString& val)
{
int i;
for ( i = 0; i < (int)val.Length(); i++)
{
if (!isalpha(val[i]))
return FALSE;
}
return TRUE;
}
static bool wxIsAlphaNumeric(const wxString& val)
{
int i;
for ( i = 0; i < (int)val.Length(); i++)
{
if (!isalnum(val[i]))
return FALSE;
}
return TRUE;
}
// Called when the value in the window must be validated.
// This function can pop up an error message.
bool wxTextValidator::Validate(wxWindow *parent)
{
if ( !m_validatorWindow )
return FALSE;
if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
return FALSE;
if ( !m_stringValue )
return FALSE;
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
// If window is disabled, don't validate
if ( !control->Enabled() )
return FALSE;
wxString val(control->GetValue());
if ( m_validatorStyle & wxFILTER_INCLUDE_LIST )
{
if ( !m_includeList.Member(val) )
{
char buf[512];
sprintf(buf, "%s is invalid.", (const char *)val);
wxMessageBox(buf, "Validation conflict", wxOK | wxICON_EXCLAMATION, parent);
return FALSE;
}
}
if ( m_validatorStyle & wxFILTER_EXCLUDE_LIST )
{
if ( m_excludeList.Member(val) )
{
char buf[512];
sprintf(buf, "%s is invalid.", (const char *)val);
wxMessageBox(buf, "Validation conflict", wxOK | wxICON_EXCLAMATION, parent);
return FALSE;
}
}
if ( (m_validatorStyle & wxFILTER_ASCII) && !val.IsAscii() )
{
char buf[512];
sprintf(buf, "%s should only contain ASCII characters.", (const char *)val);
wxMessageBox(buf, "Validation conflict", wxOK | wxICON_EXCLAMATION, parent);
return FALSE;
}
if ( (m_validatorStyle & wxFILTER_ALPHA) && !wxIsAlpha(val) )
{
char buf[512];
sprintf(buf, "%s should only contain alphabetic characters.", (const char *)val);
wxMessageBox(buf, "Validation conflict", wxOK | wxICON_EXCLAMATION, parent);
return FALSE;
}
if ( (m_validatorStyle & wxFILTER_ALPHANUMERIC) && !wxIsAlphaNumeric(val))
{
char buf[512];
sprintf(buf, "%s should only contain alphabetic or numeric characters.", (const char *)val);
wxMessageBox(buf, "Validation conflict", wxOK | wxICON_EXCLAMATION, parent);
return FALSE;
}
if ( (m_validatorStyle & wxFILTER_NUMERIC) && !val.IsNumber())
{
char buf[512];
sprintf(buf, "%s should be numeric.", (const char *)val);
wxMessageBox(buf, "Validation conflict", wxOK | wxICON_EXCLAMATION, parent);
return FALSE;
}
return TRUE ;
}
// Called to transfer data to the window
bool wxTextValidator::TransferToWindow(void)
{
if ( !m_validatorWindow )
return FALSE;
if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
return FALSE;
if ( !m_stringValue )
return FALSE;
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
control->SetValue(* m_stringValue) ;
return TRUE;
}
// Called to transfer data to the window
bool wxTextValidator::TransferFromWindow(void)
{
if ( !m_validatorWindow )
return FALSE;
if ( !m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
return FALSE;
if ( !m_stringValue )
return FALSE;
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
* m_stringValue = control->GetValue() ;
return TRUE;
}
void wxTextValidator::SetIncludeList(const wxStringList& list)
{
/*
if ( !M_VTEXTDATA )
return;
*/
m_includeList.Clear();
// TODO: replace with =
wxNode *node = list.First() ;
while ( node )
{
char *s = (char *)node->Data();
m_includeList.Add(s);
node = node->Next();
}
}
void wxTextValidator::SetExcludeList(const wxStringList& list)
{
/*
if ( !M_VTEXTDATA )
return;
*/
m_excludeList.Clear();
// TODO: replace with =
wxNode *node = list.First() ;
while ( node )
{
char *s = (char *)node->Data();
m_excludeList.Add(s);
node = node->Next();
}
}
void wxTextValidator::OnChar(wxKeyEvent& event)
{
/*
if ( !M_VTEXTDATA )
return;
*/
if ( !m_validatorWindow )
return;
wxTextCtrl *textCtrl = (wxTextCtrl *)m_validatorWindow;
int keyCode = event.KeyCode();
if ( keyCode == WXK_DELETE || keyCode == WXK_RETURN || keyCode == WXK_BACK)
{
textCtrl->wxTextCtrl::OnChar(event);
return ;
}
if ( (m_validatorStyle & wxFILTER_ASCII) && !isascii(keyCode) )
{
wxBell();
return;
}
if ( (m_validatorStyle & wxFILTER_ALPHA) && !isalpha(keyCode) )
{
wxBell();
return;
}
if ( (m_validatorStyle & wxFILTER_ALPHANUMERIC) && !isalnum(keyCode) )
{
wxBell();
return;
}
if ( (m_validatorStyle & wxFILTER_NUMERIC) && !isdigit(keyCode) && keyCode != '.' )
{
wxBell();
return;
}
textCtrl->wxTextCtrl::OnChar(event);
}

26
src/gdk_imlib/AUDIT Normal file
View File

@@ -0,0 +1,26 @@
Audit status of gdk_imlib so far:
cache.c appears clean
globals.c appears clean
load.c:
JPEG, PNG, GIF and TIFF loaders seem safe but the underlying
yet libraries have not been checked
Helper stuff should now be safe.
misc.c
The obvious screwups have been remedied with the usual
length checking sscanfs and snprintfs.
Rewrote a little of the parsing code to avoid future problems.
rend.c
Appears ok
save.c
Some stuff has been fixed. The helpers should be safe but
are incomplete
utils.c
Ok this seems clean now. There's a few FIXME's but they are
either new features (helper needs %Q) or bogus but non fatal
stuff

1
src/gdk_imlib/AUTHORS Normal file
View File

@@ -0,0 +1 @@
Rasterdude :-) <raster@redhat.com>

481
src/gdk_imlib/COPYING.LIB Normal file
View File

@@ -0,0 +1,481 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

74
src/gdk_imlib/ChangeLog Normal file
View File

@@ -0,0 +1,74 @@
1998-05-07 Raja R Harinath <harinath@cs.umn.edu>
* save.c (gdk_imlib_save_image): Replaces `snprintf' with
`g_snprintf' calls.
* utils.c (gdk_imlib_create_image_from_data): Likewise.
Tue May 5 15:11:59 1998 Radek Doulik <gis@academy.cas.cz>
* replaced snprintf calls with g_snprintf ones, so it
compiles now on SunOS
Sat Apr 11 12:30:13 1998 George Lebl <jirka@5z.com>
* utils.c: fixed yet one more SIGFPE on alpha
Fri Mar 20 00:02:43 1998 Tom Tromey <tromey@cygnus.com>
* gdk_imlib.h: Replaced `()' with `(void)'.
Sun Mar 15 12:34:45 1998 Owen Taylor <owt1@cornell.edu>
* Makefile.am (INCLUDES): Added GTK_CFLAGS
1998-02-25 Raja R Harinath <harinath@cs.umn.edu>
* Makefile.am (DEFS): Define `SYSTEM_IMRC' too.
1998-02-25 Federico Mena Quintero <federico@nuclecu.unam.mx>
* misc.c (gdk_imlib_copy_image): The drawable passed to gdk_gc_new
should be the dest drawable, not the base imlib window. This
caused BadMatches all over the place (especially in copy_mask).
(gdk_imlib_copy_mask): Likewise.
1998-02-24 Raja R Harinath <harinath@cs.umn.edu>
* Makefile.am (DEFS): New var. Moved stuff from CFLAGS.
(INCLUDES): New var.
1998-02-24 Mark Galassi <rosalia@cygnus.com>
* Makefile.am (libgdk_imlib_la_SOURCES):
(lib_LTLIBRARIES): changed gdk_imlib to use the libtool+automake
formalisms.
* load.c (gdk_imlib_load_image): changed JPEG_PATH to DJPEG_PROG
and removed %s/djpeg, sine DJPEG_PROG is the full program path.
1998-02-17 Federico Mena Quintero <federico@nuclecu.unam.mx>
* Makefile.in (install): Make directory for config files.
* configure.in: Fixed ENL_LIB_SUPPORT function for non-existing libraries.
1998-02-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* misc.c (gdk_imlib_init): I create a colormap specific to the
visual the base_window will be using. This fixes BadMatch errors
on machines with multiple visual/depth combinations.
1998-02-17 The Rasterman <raster@redhat.com>
* misc.c (gdk_imlib_init) Fixed visual stuff slightly, and Colormap
creation (so it only does so if the visual for the default and the
chosen visual mismatch), added function calls to retrieve Imlib's
visual and Colormap, plus endianess fixes for network displaying.
1998-02-17 The Rasterman <raster@redhat.com>
added system imrc config return function
1998-02-18 The Rasterman <raster@redhat.com>
Fixed load.c - missed a not (!) in an if clause

29
src/gdk_imlib/README Normal file
View File

@@ -0,0 +1,29 @@
-------------------------------------------------------------------------------
I M L I B
1.4
-------------------------------------------------------------------------------
This software is Copyright (C) 1998 By The Rasterman (Carsten Haitzler). I
accept no responsability for anythign this software may or may not do to
your system - you use it completely at your own risk. This software comes
under the LGPL and GPL licences. The library itself is LGPL (all software in
Imlib and gdk_imlib directories) see the COPYING and COPYING.LIB files for
full legal details.
-------------------------------------------------------------------------------
If you have picked up a net release of imlib you should be able to
just follow the instructions in the INSTALL file.
If you are using imlib out of the CVS repository, then you need to
have some extra tools installed, and the configuration process is
lengthier. the HACKING file has all the details for building from a
CVS checkout.
Imlib will run MARKEDLY better if you get certain libraries. Notably,
libjpeg, libpng, libtiff and libgif. For more information please go look at:
http://www.labs.redhat.com/imlib/
This will give links to everything you need or may want for Imlib's optimal
functionality.

496
src/gdk_imlib/cache.c Normal file
View File

@@ -0,0 +1,496 @@
#define _GNU_SOURCE
#include "gdk_imlib.h"
#include "gdk_imlib_private.h"
/* uncomment this to compile imlib's cahce with pixmap accounting output */
/*#define PIXMAP_ACCOUNTING */
void
gdirty_pixmaps(GdkImlibImage * im)
{
struct pixmap_cache *ptr;
ptr = id->cache.pixmap;
while (ptr)
{
if ((ptr->im == im) && ((!ptr->file) || (!strcmp(im->filename, ptr->file))))
ptr->dirty = 1;
ptr = ptr->next;
}
}
void
gdirty_images(GdkImlibImage * im)
{
struct image_cache *ptr;
ptr = id->cache.image;
while (ptr)
{
if ((!strcmp(im->filename, ptr->file)) && (im == ptr->im))
{
ptr->dirty = 1;
return;
}
ptr = ptr->next;
}
}
void
gfind_pixmap(GdkImlibImage * im, int width, int height, GdkPixmap ** pmap, GdkBitmap ** mask)
{
struct pixmap_cache *ptr;
ptr = id->cache.pixmap;
while (ptr)
{
if ((ptr->im == im) && (ptr->width == width) && (ptr->height == height) &&
((!ptr->file) || (!strcmp(im->filename, ptr->file))) &&
(!ptr->dirty))
{
if (ptr->refnum > 0)
ptr->refnum++;
else
{
ptr->refnum++;
id->cache.num_pixmap++;
if (ptr->pmap)
id->cache.used_pixmap -= width * height * id->x.depth;
if (ptr->shape_mask)
id->cache.used_pixmap -= width * height;
if (id->cache.used_pixmap < 0)
{
id->cache.used_pixmap = 0;
fprintf(stderr, "IMLIB: uhoh.. caching problems.... meep meep\n");
}
}
if (ptr->prev)
{
ptr->prev->next = ptr->next;
if (ptr->next)
ptr->next->prev = ptr->prev;
ptr->next = id->cache.pixmap;
ptr->next->prev = ptr;
id->cache.pixmap = ptr;
ptr->prev = NULL;
}
*pmap = ptr->pmap;
*mask = ptr->shape_mask;
return;
}
ptr = ptr->next;
}
*pmap = NULL;
*mask = NULL;
}
GdkImlibImage *
gfind_image(char *file)
{
struct image_cache *ptr;
ptr = id->cache.image;
while (ptr)
{
if ((!strcmp(file, ptr->file)) && (!ptr->dirty))
{
if (ptr->refnum)
ptr->refnum++;
else
{
ptr->refnum++;
id->cache.num_image++;
id->cache.used_image -= ptr->im->rgb_width * ptr->im->rgb_height * 3;
if (id->cache.used_image < 0)
{
id->cache.used_image = 0;
fprintf(stderr, "IMLIB: uhoh.. caching problems.... meep meep\n");
}
}
if (ptr->prev)
{
ptr->prev->next = ptr->next;
if (ptr->next)
ptr->next->prev = ptr->prev;
ptr->next = id->cache.image;
ptr->next->prev = ptr;
id->cache.image = ptr;
ptr->prev = NULL;
}
return ptr->im;
}
ptr = ptr->next;
}
return NULL;
}
void
gfree_pixmappmap(GdkPixmap * pmap)
{
struct pixmap_cache *ptr;
ptr = id->cache.pixmap;
while (ptr)
{
if ((ptr->pmap == pmap) || (ptr->shape_mask == pmap))
{
if (ptr->shape_mask == pmap)
return;
if (ptr->refnum > 0)
{
ptr->refnum--;
if (ptr->refnum == 0)
{
id->cache.num_pixmap--;
if (ptr->pmap)
id->cache.used_pixmap += ptr->width * ptr->height * id->x.depth;
if (ptr->shape_mask)
id->cache.used_pixmap += ptr->width * ptr->height;
}
}
return;
}
ptr = ptr->next;
}
gdk_pixmap_unref(pmap);
}
void
gfree_image(GdkImlibImage * im)
{
struct image_cache *ptr;
ptr = id->cache.image;
while (ptr)
{
if (im == ptr->im)
{
if (ptr->refnum)
{
ptr->refnum--;
if (!ptr->refnum)
{
id->cache.num_image--;
id->cache.used_image += ptr->im->rgb_width * ptr->im->rgb_height * 3;
}
}
return;
}
ptr = ptr->next;
}
gnullify_image(im);
}
void
gflush_image(GdkImlibImage * im)
{
if (im)
im->cache = 0;
}
void
gadd_image(GdkImlibImage * im, char *file)
{
struct image_cache *ptr;
struct image_cache *n;
if ((!im) || (!file))
return;
ptr = id->cache.image;
n = malloc(sizeof(struct image_cache));
if (!n)
return;
n->prev = NULL;
n->next = ptr;
n->file = malloc(strlen(file) + 1);
if (!n->file)
{
free(n);
return;
}
strcpy(n->file, file);
n->im = im;
n->refnum = 1;
n->dirty = 0;
if (n->next)
n->next->prev = n;
id->cache.image = n;
id->cache.num_image++;
}
void
gadd_pixmap(GdkImlibImage * im, int width, int height, XImage * xim, XImage * sxim)
{
struct pixmap_cache *ptr;
struct pixmap_cache *n;
if (!im)
return;
ptr = id->cache.pixmap;
n = malloc(sizeof(struct pixmap_cache));
if (!n)
return;
n->prev = NULL;
n->next = ptr;
n->im = im;
if (im->filename)
{
n->file = malloc(strlen(im->filename) + 1);
if (n->file)
strcpy(n->file, im->filename);
}
else
n->file = NULL;
n->refnum = 1;
n->dirty = 0;
n->width = width;
n->height = height;
n->pmap = im->pixmap;
n->shape_mask = im->shape_mask;
n->xim = xim;
n->sxim = sxim;
if (n->next)
n->next->prev = n;
id->cache.pixmap = n;
id->cache.num_pixmap++;
}
void
gclean_caches()
{
{
struct image_cache *ptr = NULL;
struct image_cache *pptr = NULL;
struct image_cache *last = NULL;
int newlast;
/* find the back of the list */
ptr = id->cache.image;
while (ptr)
{
last = ptr;
ptr = ptr->next;
}
newlast = 0;
ptr = last;
/* remove all images that are tagged non-cachable, and have 0 */
/* references , even if the cache has spare room. */
while (ptr)
{
if (!ptr->refnum)
{
if (!ptr->im->cache)
{
if (ptr == last)
newlast = 1;
id->cache.used_image -= ptr->im->rgb_width * ptr->im->rgb_height * 3;
gnullify_image(ptr->im);
if (pptr)
ptr = pptr->prev;
if (ptr->prev)
ptr->prev->next = ptr->next;
else
id->cache.image = ptr->next;
if (ptr->next)
ptr->next->prev = ptr->prev;
if (ptr->file)
free(ptr->file);
free(ptr);
ptr = NULL;
}
}
if (ptr)
ptr = ptr->prev;
if (newlast)
{
last = NULL;
ptr = id->cache.image;
while (ptr)
{
last = ptr;
ptr = ptr->next;
}
newlast = 0;
ptr = last;
}
}
/* find the back of the list */
ptr = id->cache.image;
last = NULL;
while (ptr)
{
last = ptr;
ptr = ptr->next;
}
newlast = 0;
ptr = last;
/* while the amount of data in the cache is greater than the set */
/* amount, delete the last entry (last used) from the unreferenced */
/* cached 24-bit images */
while (id->cache.used_image > id->cache.size_image)
{
while (ptr)
{
if (ptr->refnum < 1)
{
if (ptr == last)
newlast = 1;
id->cache.used_image -= ptr->im->rgb_width * ptr->im->rgb_height * 3;
gnullify_image(ptr->im);
if (ptr->prev)
ptr->prev->next = ptr->next;
else
id->cache.image = ptr->next;
if (ptr->next)
ptr->next->prev = ptr->prev;
if (ptr->file)
free(ptr->file);
free(ptr);
ptr = NULL;
break;
}
if (ptr)
ptr = ptr->prev;
}
if (newlast)
{
last = NULL;
ptr = id->cache.image;
while (ptr)
{
last = ptr;
ptr = ptr->next;
}
newlast = 0;
ptr = last;
}
if (!ptr)
break;
}
}
{
struct pixmap_cache *ptr;
struct pixmap_cache *last;
int newlast;
#ifdef PIXMAP_ACCOUNTING
int total, total2, num, num2;
printf("--------- Pixmap cashe zise %i / %i with %i pixmaps referenced\n",
id->cache.used_pixmap, id->cache.size_pixmap,
id->cache.num_pixmap);
ptr = id->cache.pixmap;
total = 0;
total2 = 0;
num = 0;
num2 = 0;
while (ptr)
{
printf("Pmap for file %s REFNUM %3i SIZE %4ix%4i PMAP %8x MASK %8x\n",
ptr->file, ptr->refnum, ptr->width, ptr->height, ptr->pmap,
ptr->shape_mask);
if (ptr->refnum > 0)
{
total += (ptr->width * ptr->height * id->x.depth);
if (ptr->shape_mask)
total += (ptr->width * ptr->height);
num++;
}
else
{
total2 += (ptr->width * ptr->height * id->x.depth);
if (ptr->shape_mask)
total2 += (ptr->width * ptr->height);
num2++;
}
ptr = ptr->next;
}
printf("Accounting Data:\n");
printf("*** total pixmap's in cache %i with %i pixmaps\n",
total, num);
printf("*** total unreffed pixmap's in cache %i with %i pixmaps\n\n",
total2, num2);
#endif
/* find the back of the list */
ptr = id->cache.pixmap;
last = NULL;
while (ptr)
{
last = ptr;
ptr = ptr->next;
}
newlast = 0;
ptr = last;
/* while the amount of data in the cache is greater than the set */
/* amount, delete the last entry (last used) from the unreferenced */
/* cached pixmaps */
while (id->cache.used_pixmap > id->cache.size_pixmap)
{
while (ptr)
{
if (ptr->refnum < 1)
{
if (ptr == last)
newlast = 1;
if (ptr->pmap)
id->cache.used_pixmap -= ptr->width * ptr->height * id->x.depth;
if (ptr->shape_mask)
id->cache.used_pixmap -= ptr->width * ptr->height;
if (ptr->pmap)
gdk_pixmap_unref(ptr->pmap);
if (ptr->shape_mask)
gdk_pixmap_unref(ptr->shape_mask);
if (ptr->xim)
XDestroyImage(ptr->xim);
if (ptr->sxim)
XDestroyImage(ptr->sxim);
if (ptr->prev)
ptr->prev->next = ptr->next;
else
id->cache.pixmap = ptr->next;
if (ptr->next)
ptr->next->prev = ptr->prev;
if (ptr->file)
free(ptr->file);
free(ptr);
ptr = NULL;
break;
}
if (ptr)
ptr = ptr->prev;
}
if (newlast)
{
last = NULL;
ptr = id->cache.pixmap;
while (ptr)
{
last = ptr;
ptr = ptr->next;
}
newlast = 0;
ptr = last;
}
if (!ptr)
break;
}
}
}
void
gnullify_image(GdkImlibImage * im)
{
if (!im)
return;
if (im->rgb_data)
free(im->rgb_data);
if (im->alpha_data)
free(im->alpha_data);
if (im->pixmap)
gfree_pixmappmap(im->pixmap);
if (im->filename)
free(im->filename);
free(im);
}

113
src/gdk_imlib/colors.c Normal file
View File

@@ -0,0 +1,113 @@
#define _GNU_SOURCE
#include "gdk_imlib.h"
#include "gdk_imlib_private.h"
void
g_PaletteAlloc(int num, int *cols)
{
XColor xcl;
int i;
int r, g, b;
if (id->palette)
free(id->palette);
id->palette = malloc(sizeof(GdkImlibColor) * num);
if (id->palette_orig)
free(id->palette_orig);
id->palette_orig = malloc(sizeof(GdkImlibColor) * num);
for (i = 0; i < num; i++)
{
r = cols[(i * 3) + 0];
g = cols[(i * 3) + 1];
b = cols[(i * 3) + 2];
xcl.red = (unsigned short)((r << 8) | (r));
xcl.green = (unsigned short)((g << 8) | (g));
xcl.blue = (unsigned short)((b << 8) | (b));
xcl.flags = DoRed | DoGreen | DoBlue;
XAllocColor(id->x.disp, id->x.root_cmap, &xcl);
id->palette[i].r = xcl.red >> 8;
id->palette[i].g = xcl.green >> 8;
id->palette[i].b = xcl.blue >> 8;
id->palette[i].pixel = xcl.pixel;
id->palette_orig[i].r = r;
id->palette_orig[i].g = g;
id->palette_orig[i].b = b;
id->palette_orig[i].pixel = xcl.pixel;
}
id->num_colors = num;
}
gint
gdk_imlib_load_colors(char *file)
{
FILE *f;
char s[256];
int i;
int pal[768];
int r, g, b;
int rr, gg, bb;
f = fopen(file, "r");
if (!f)
{
fprintf(stderr, "GImLib ERROR: Cannot find palette file %s\n", file);
return 0;
}
i = 0;
while (fgets(s, 256, f))
{
if (s[0] == '0')
{
sscanf(s, "%x %x %x", &r, &g, &b);
if (r < 0)
r = 0;
if (r > 255)
r = 255;
if (g < 0)
g = 0;
if (g > 255)
g = 255;
if (b < 0)
b = 0;
if (b > 255)
b = 255;
pal[i++] = r;
pal[i++] = g;
pal[i++] = b;
}
if (i >= 768)
break;
}
fclose(f);
g_PaletteAlloc((i / 3), pal);
if (id->fast_rgb)
free(id->fast_rgb);
id->fast_rgb = malloc(sizeof(int) * 32 * 32 * 32);
for (r = 0; r < 32; r++)
{
for (g = 0; g < 32; g++)
{
for (b = 0; b < 32; b++)
{
rr = (r << 3) | (r >> 2);
gg = (g << 3) | (g >> 2);
bb = (b << 3) | (b >> 2);
INDEX_RGB(r, g, b) = gindex_best_color_match(&rr, &gg, &bb);
}
}
}
return 1;
}
void
gdk_imlib_free_colors()
{
int i;
unsigned long pixels[256];
for (i = 0; i < id->num_colors; i++)
pixels[i] = id->palette[i].pixel;
XFreeColors(id->x.disp, id->x.root_cmap, pixels, id->num_colors, 0);
id->num_colors = 0;
}

2
src/gdk_imlib/config.h Normal file
View File

@@ -0,0 +1,2 @@
#undef PACKAGE
#undef VERSION

76
src/gdk_imlib/gdk_imlib.h Normal file
View File

@@ -0,0 +1,76 @@
#ifndef __GDK_IMLIB_H__
#define __GDK_IMLIB_H__
#include <gdk_imlib_types.h>
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
void gdk_imlib_init(void);
void gdk_imlib_init_params(GdkImlibInitParams * p);
gint gdk_imlib_get_render_type(void);
void gdk_imlib_set_render_type(gint rend_type);
gint gdk_imlib_load_colors(char *file);
GdkImlibImage *gdk_imlib_load_image(char *file);
gint gdk_imlib_best_color_match(gint * r, gint * g, gint * b);
gint gdk_imlib_render(GdkImlibImage * image, gint width, gint height);
GdkPixmap *gdk_imlib_copy_image(GdkImlibImage * image);
GdkBitmap *gdk_imlib_copy_mask(GdkImlibImage * image);
GdkPixmap *gdk_imlib_move_image(GdkImlibImage * image);
GdkBitmap *gdk_imlib_move_mask(GdkImlibImage * image);
void gdk_imlib_destroy_image(GdkImlibImage * image);
void gdk_imlib_kill_image(GdkImlibImage * image);
void gdk_imlib_free_colors(void);
void gdk_imlib_free_pixmap(GdkPixmap * pixmap);
void gdk_imlib_free_bitmap(GdkBitmap * bitmap);
void gdk_imlib_get_image_border(GdkImlibImage * image, GdkImlibBorder * border);
void gdk_imlib_set_image_border(GdkImlibImage * image, GdkImlibBorder * border);
void gdk_imlib_get_image_shape(GdkImlibImage * image, GdkImlibColor * color);
void gdk_imlib_set_image_shape(GdkImlibImage * image, GdkImlibColor * color);
gint gdk_imlib_save_image_to_eim(GdkImlibImage * image, char *file);
gint gdk_imlib_add_image_to_eim(GdkImlibImage * image, char *file);
gint gdk_imlib_save_image_to_ppm(GdkImlibImage * image, char *file);
gint gdk_imlib_load_file_to_pixmap(char *filename, GdkPixmap ** pmap, GdkBitmap ** mask);
void gdk_imlib_set_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_set_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_set_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_set_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_get_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_get_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_get_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_get_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod);
void gdk_imlib_set_image_red_curve(GdkImlibImage * im, unsigned char *mod);
void gdk_imlib_set_image_green_curve(GdkImlibImage * im, unsigned char *mod);
void gdk_imlib_set_image_blue_curve(GdkImlibImage * im, unsigned char *mod);
void gdk_imlib_get_image_red_curve(GdkImlibImage * im, unsigned char *mod);
void gdk_imlib_get_image_green_curve(GdkImlibImage * im, unsigned char *mod);
void gdk_imlib_get_image_blue_curve(GdkImlibImage * im, unsigned char *mod);
void gdk_imlib_apply_modifiers_to_rgb(GdkImlibImage * im);
void gdk_imlib_changed_image(GdkImlibImage * im);
void gdk_imlib_apply_image(GdkImlibImage * im, GdkWindow * p);
void gdk_imlib_paste_image(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h);
void gdk_imlib_paste_image_border(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h);
void gdk_imlib_flip_image_horizontal(GdkImlibImage * im);
void gdk_imlib_flip_image_vertical(GdkImlibImage * im);
void gdk_imlib_rotate_image(GdkImlibImage * im, gint d);
GdkImlibImage *gdk_imlib_create_image_from_data(unsigned char *data, unsigned char *alpha, gint w, gint h);
GdkImlibImage *gdk_imlib_clone_image(GdkImlibImage * im);
GdkImlibImage *gdk_imlib_clone_scaled_image(GdkImlibImage * im, int w, int h);
gint gdk_imlib_get_fallback(void);
void gdk_imlib_set_fallback(gint fallback);
GdkVisual *gdk_imlib_get_visual(void);
GdkColormap *gdk_imlib_get_colormap(void);
gchar *gdk_imlib_get_sysconfig(void);
GdkImlibImage *gdk_imlib_create_image_from_xpm_data(char **data);
gint gdk_imlib_data_to_pixmap(char **data, GdkPixmap ** pmap, GdkBitmap ** mask);
void gdk_imlib_crop_image(GdkImlibImage * im, gint x, gint y, gint w, gint h);
gint gdk_imlib_save_image(GdkImlibImage * im, char *file, GdkImlibSaveInfo * info);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,226 @@
#ifdef _HAVE_STRING_H
#include <string.h>
#elif _HAVE_STRINGS_H
#include <strings.h>
#endif
#ifndef CONVERT_PATH
#define CONVERT_PATH "/usr/local/bin"
#endif
#ifndef NETPBM_PATH
#define NETPBM_PATH "/usr/local/bin"
#endif
#ifndef CJPEG_PROG
#define CJPEG_PROG "/usr/bin/cjpeg"
#endif
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <time.h>
#include <netinet/in.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef _HAVE_STRING_H
#include <string.h>
#elif _HAVE_STRINGS_H
#include <strings.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/shape.h>
#include <X11/cursorfont.h>
#include <gdk/gdkprivate.h>
#ifdef HAVE_LIBJPEG
#include <jpeglib.h>
#endif
#ifdef HAVE_LIBPNG
#include <png.h>
#endif
#ifdef HAVE_LIBTIFF
#include <tiffio.h>
#endif
#ifdef HAVE_LIBGIF
#include <gif_lib.h>
#endif
#define BYTE_ORD_24_RGB 0
#define BYTE_ORD_24_RBG 1
#define BYTE_ORD_24_BRG 2
#define BYTE_ORD_24_BGR 3
#define BYTE_ORD_24_GRB 4
#define BYTE_ORD_24_GBR 5
struct image_cache
{
gchar *file;
GdkImlibImage *im;
gint refnum;
gchar dirty;
struct image_cache *prev;
struct image_cache *next;
};
struct pixmap_cache
{
GdkImlibImage *im;
gchar *file;
gchar dirty;
gint width, height;
GdkPixmap *pmap;
GdkBitmap *shape_mask;
XImage *xim, *sxim;
gint refnum;
struct pixmap_cache *prev;
struct pixmap_cache *next;
};
typedef struct _xdata
{
Display *disp;
gint screen;
Window root;
Visual *visual;
gint depth;
gint render_depth;
Colormap root_cmap;
gchar shm;
gchar shmp;
gint shm_event;
XImage *last_xim;
XImage *last_sxim;
XShmSegmentInfo last_shminfo;
XShmSegmentInfo last_sshminfo;
Window base_window;
GdkWindow *gdk_win;
GdkColormap *gdk_cmap;
}
Xdata;
typedef struct _imlibdata
{
gint num_colors;
GdkImlibColor *palette;
GdkImlibColor *palette_orig;
unsigned char *fast_rgb;
gint *fast_err;
gint *fast_erg;
gint *fast_erb;
gint render_type;
gint max_shm;
Xdata x;
gint byte_order;
struct _cache
{
gchar on_image;
gint size_image;
gint num_image;
gint used_image;
struct image_cache *image;
gchar on_pixmap;
gint size_pixmap;
gint num_pixmap;
gint used_pixmap;
struct pixmap_cache *pixmap;
}
cache;
gchar fastrend;
gchar hiq;
GdkImlibColorModifier mod, rmod, gmod, bmod;
unsigned char rmap[256], gmap[256], bmap[256];
gchar fallback;
gchar ordered_dither;
}
ImlibData;
extern ImlibData *id;
gint gindex_best_color_match(gint * r, gint * g, gint * b);
void gdirty_pixmaps(GdkImlibImage * im);
void gdirty_images(GdkImlibImage * im);
void gfind_pixmap(GdkImlibImage * im, int width, int height, GdkPixmap ** pmap, GdkBitmap ** mask);
GdkImlibImage *gfind_image(char *file);
void gfree_pixmappmap(GdkPixmap * pmap);
void gfree_image(GdkImlibImage * im);
void gflush_image(GdkImlibImage * im);
void gadd_image(GdkImlibImage * im, char *file);
void gadd_pixmap(GdkImlibImage * im, int width, int height, XImage * xim, XImage * sxim);
void gclean_caches();
void gnullify_image(GdkImlibImage * im);
/* char *g_SplitID(char *file); */
char *g_GetExtension(char *file);
#ifdef HAVE_LIBJPEG
unsigned char *g_LoadJPEG(FILE * f, int *w, int *h);
#endif /* HAVE_LIBJPEG */
#ifdef HAVE_LIBPNG
unsigned char *g_LoadPNG(FILE * f, int *w, int *h, int *t);
#endif /* HAVE_LIBPNG */
#ifdef HAVE_LIBTIFF
unsigned char *g_LoadTIFF(char *f, int *w, int *h, int *t);
#endif /* HAVE_LIBTIFF */
#ifdef HAVE_LIBGIF
unsigned char *g_LoadGIF(char *f, int *w, int *h, int *t);
#endif /* HAVE_LIBGIF */
unsigned char *g_LoadXPM(char *f, int *w, int *h, int *t);
unsigned char *g_LoadPPM(FILE * f, int *w, int *h);
/*
static int gispnm(char *file);
static int gisjpeg(char *file);
static int gispng(char *file);
static int gistiff(char *file);
static int giseim(char *file);
static int gisgif(char *file);
static int gisxpm(char *file);
*/
GdkPixmap *gdk_imlib_pixmap_foreign_new(gint width, gint height, gint depth, Pixmap pmap);
void gcalc_map_tables(GdkImlibImage * im);
void g_PaletteAlloc(int num, int *cols);
FILE *open_helper(const char *, const char *, const char *);
int close_helper(FILE *);
#define INDEX_RGB(r,g,b) id->fast_rgb[(r<<10)|(g<<5)|(b)]
#define COLOR_INDEX(i) id->palette[i].pixel
#define COLOR_RGB(r,g,b) id->palette[INDEX_RGB(r,g,b)].pixel
#define ERROR_RED(rr,i) rr-id->palette[i].r;
#define ERROR_GRN(gg,i) gg-id->palette[i].g;
#define ERROR_BLU(bb,i) bb-id->palette[i].b;
#define DITHER_ERROR(Der1,Der2,Dex,Der,Deg,Deb) \
ter=&(Der1[Dex]);\
(*ter)+=(Der*7)>>4;ter++;\
(*ter)+=(Deg*7)>>4;ter++;\
(*ter)+=(Deb*7)>>4;\
ter=&(Der2[Dex-6]);\
(*ter)+=(Der*3)>>4;ter++;\
(*ter)+=(Deg*3)>>4;ter++;\
(*ter)+=(Deb*3)>>4;ter++;\
(*ter)+=(Der*5)>>4;ter++;\
(*ter)+=(Deg*5)>>4;ter++;\
(*ter)+=(Deb*5)>>4;ter++;\
(*ter)+=Der>>4;ter++;\
(*ter)+=Deg>>4;ter++;\
(*ter)+=Deb>>4;

View File

@@ -0,0 +1,101 @@
#include <gdk/gdk.h>
#ifndef SYSTEM_IMRC
#define SYSTEM_IMRC "/etc/imrc"
#endif /* endef SYSTEM_IMRC */
typedef struct _GdkImlibBorder
{
gint left, right;
gint top, bottom;
}
GdkImlibBorder;
typedef struct _GdkImlibColor
{
gint r, g, b;
gint pixel;
}
GdkImlibColor;
typedef struct _GdkImlibColorModifier
{
gint gamma;
gint brightness;
gint contrast;
}
GdkImlibColorModifier;
typedef struct _GdkImlibImage
{
gint rgb_width, rgb_height;
unsigned char *rgb_data;
unsigned char *alpha_data;
gchar *filename;
/* the below information is private */
gint width, height;
GdkImlibColor shape_color;
GdkImlibBorder border;
GdkPixmap *pixmap;
GdkBitmap *shape_mask;
gchar cache;
GdkImlibColorModifier mod, rmod, gmod, bmod;
unsigned char rmap[256], gmap[256], bmap[256];
}
GdkImlibImage;
typedef struct _GdkImlibSaveInfo
{
int quality;
int scaling;
int xjustification;
int yjustification;
int page_size;
char color;
}
GdkImlibSaveInfo;
typedef struct _GdkImlibInitParams
{
int flags;
int visualid;
char *palettefile;
char sharedmem;
char sharedpixmaps;
char paletteoverride;
char remap;
char fastrender;
char hiquality;
char dither;
int imagecachesize;
int pixmapcachesize;
}
GdkImlibInitParams;
#define PARAMS_VISUALID 1<<0
#define PARAMS_PALETTEFILE 1<<1
#define PARAMS_SHAREDMEM 1<<2
#define PARAMS_SHAREDPIXMAPS 1<<3
#define PARAMS_PALETTEOVERRIDE 1<<4
#define PARAMS_REMAP 1<<5
#define PARAMS_FASTRENDER 1<<6
#define PARAMS_HIQUALITY 1<<7
#define PARAMS_DITHER 1<<8
#define PARAMS_IMAGECACHESIZE 1<<9
#define PARAMS_PIXMAPCACHESIZE 1<<10
#define PAGE_SIZE_EXECUTIVE 0
#define PAGE_SIZE_LETTER 1
#define PAGE_SIZE_LEGAL 2
#define PAGE_SIZE_A4 3
#define PAGE_SIZE_A3 4
#define PAGE_SIZE_A5 5
#define PAGE_SIZE_FOLIO 6
#define RT_PLAIN_PALETTE 0
#define RT_PLAIN_PALETTE_FAST 1
#define RT_DITHER_PALETTE 2
#define RT_DITHER_PALETTE_FAST 3
#define RT_PLAIN_TRUECOL 4
/* a special high-quality renderer for people with 15 and 16bpp that dithers */
#define RT_DITHER_TRUECOL 5

6
src/gdk_imlib/globals.c Normal file
View File

@@ -0,0 +1,6 @@
#define _GNU_SOURCE
#include "gdk_imlib.h"
#include "gdk_imlib_private.h"
ImlibData *id;

1494
src/gdk_imlib/load.c Normal file

File diff suppressed because it is too large Load Diff

1165
src/gdk_imlib/misc.c Normal file

File diff suppressed because it is too large Load Diff

6170
src/gdk_imlib/rend.c Normal file

File diff suppressed because it is too large Load Diff

538
src/gdk_imlib/save.c Normal file
View File

@@ -0,0 +1,538 @@
#define _GNU_SOURCE
#include <config.h>
#include "gdk_imlib.h"
#include "gdk_imlib_private.h"
gint
gdk_imlib_save_image(GdkImlibImage * im, char *file, GdkImlibSaveInfo * info)
{
char *ext;
char cmd[10240];
FILE *f;
GdkImlibSaveInfo defaults;
if (!im || !file)
return 0;
defaults.quality = 208;
defaults.scaling = 1024;
defaults.xjustification = 512;
defaults.yjustification = 512;
defaults.page_size = PAGE_SIZE_LETTER;
defaults.color = 1;
if (!info)
info = &defaults;
ext = g_GetExtension(file);
if ((!strcasecmp(ext, "ppm")) || (!strcasecmp(ext, "pnm")))
{
f = fopen(file, "wb");
if (f)
{
if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height))
{
fclose(f);
return 0;
}
if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f))
{
fclose(f);
return 0;
}
fclose(f);
return 1;
}
}
else if (!strcasecmp(ext, "pgm"))
{
int x, y;
unsigned char *ptr, val;
int v;
f = fopen(file, "wb");
if (f)
{
if (!fprintf(f, "P5\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height))
{
fclose(f);
return 0;
}
ptr = im->rgb_data;
for (y = 0; y < im->rgb_height; y++)
{
for (x = 0; x < im->rgb_width; x++)
{
v = (int)(*ptr++);
v += (int)(*ptr++);
v += (int)(*ptr++);
val = (unsigned char)(v / 3);
if (!fwrite(&val, 1, 1, f))
{
fclose(f);
return 0;
}
}
}
fclose(f);
return 1;
}
}
else if (!strcasecmp(ext, "ps"))
{
int bx, by, bxx, byy;
int w, h;
int sx, sy;
int tx = 35, ty = 35;
int x, y;
unsigned char *ptr;
int v;
f = fopen(file, "wb");
if (f == NULL)
return 0;
w = im->rgb_width;
h = im->rgb_height;
switch (info->page_size)
{
case PAGE_SIZE_EXECUTIVE:
sx = 540;
sy = 720;
break;
case PAGE_SIZE_LETTER:
sx = 612;
sy = 792;
break;
case PAGE_SIZE_LEGAL:
sx = 612;
sy = 1008;
break;
case PAGE_SIZE_A4:
sx = 595;
sy = 842;
break;
case PAGE_SIZE_A3:
sx = 842;
sy = 1190;
break;
case PAGE_SIZE_A5:
sx = 420;
sy = 595;
break;
case PAGE_SIZE_FOLIO:
sx = 612;
sy = 936;
break;
}
bxx = ((sx - (tx * 2)) * info->scaling) >> 10;
byy = ((h * bxx / w) * info->scaling) >> 10;
if ((((sy - (ty * 2)) * info->scaling) >> 10) < byy)
{
byy = ((sy - (ty * 2)) * info->scaling) >> 10;
bxx = ((w * byy / h) * info->scaling) >> 10;
}
bx = tx + ((((sx - (tx * 2)) - bxx) * info->xjustification) >> 10);
by = ty + ((((sy - (ty * 2)) - byy) * info->yjustification) >> 10);
if (f)
{
fprintf(f, "%%!PS-Adobe-2.0 EPSF-2.0\n");
fprintf(f, "%%%%Title: %s\n", file);
fprintf(f, "%%%%Creator: Imlib by The Rasterman\n");
fprintf(f, "%%%%BoundingBox: %i %i %i %i\n", bx, by, bxx, byy);
fprintf(f, "%%%%Pages: 1\n");
fprintf(f, "%%%%DocumentFonts:\n");
fprintf(f, "%%%%EndComments\n");
fprintf(f, "%%%%EndProlog\n");
fprintf(f, "%%%%Page: 1 1\n");
fprintf(f, "/origstate save def\n");
fprintf(f, "20 dict begin\n");
if (info->color)
{
fprintf(f, "/pix %i string def\n", w * 3);
fprintf(f, "/grays %i string def\n", w);
fprintf(f, "/npixls 0 def\n");
fprintf(f, "/rgbindx 0 def\n");
fprintf(f, "%i %i translate\n", bx, by);
fprintf(f, "%i %i scale\n", bxx, byy);
fprintf(f,
"/colorimage where\n"
"{ pop }\n"
"{\n"
"/colortogray {\n"
"/rgbdata exch store\n"
"rgbdata length 3 idiv\n"
"/npixls exch store\n"
"/rgbindx 0 store\n"
"0 1 npixls 1 sub {\n"
"grays exch\n"
"rgbdata rgbindx get 20 mul\n"
"rgbdata rgbindx 1 add get 32 mul\n"
"rgbdata rgbindx 2 add get 12 mul\n"
"add add 64 idiv\n"
"put\n"
"/rgbindx rgbindx 3 add store\n"
"} for\n"
"grays 0 npixls getinterval\n"
"} bind def\n"
"/mergeprocs {\n"
"dup length\n"
"3 -1 roll\n"
"dup\n"
"length\n"
"dup\n"
"5 1 roll\n"
"3 -1 roll\n"
"add\n"
"array cvx\n"
"dup\n"
"3 -1 roll\n"
"0 exch\n"
"putinterval\n"
"dup\n"
"4 2 roll\n"
"putinterval\n"
"} bind def\n"
"/colorimage {\n"
"pop pop\n"
"{colortogray} mergeprocs\n"
"image\n"
"} bind def\n"
"} ifelse\n");
fprintf(f, "%i %i 8\n", w, h);
fprintf(f, "[%i 0 0 -%i 0 %i]\n", w, h, h);
fprintf(f, "{currentfile pix readhexstring pop}\n");
fprintf(f, "false 3 colorimage\n");
fprintf(f, "\n");
ptr = im->rgb_data;
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
v = (int)(*ptr++);
if (v < 0x10)
fprintf(f, "0%x", v);
else
fprintf(f, "%x", v);
v = (int)(*ptr++);
if (v < 0x10)
fprintf(f, "0%x", v);
else
fprintf(f, "%x", v);
v = (int)(*ptr++);
if (v < 0x10)
fprintf(f, "0%x", v);
else
fprintf(f, "%x", v);
}
fprintf(f, "\n");
}
}
else
{
fprintf(f, "/pix %i string def\n", w);
fprintf(f, "/grays %i string def\n", w);
fprintf(f, "/npixls 0 def\n");
fprintf(f, "/rgbindx 0 def\n");
fprintf(f, "%i %i translate\n", bx, by);
fprintf(f, "%i %i scale\n", bxx, byy);
fprintf(f, "%i %i 8\n", w, h);
fprintf(f, "[%i 0 0 -%i 0 %i]\n", w, h, h);
fprintf(f, "{currentfile pix readhexstring pop}\n");
fprintf(f, "image\n");
fprintf(f, "\n");
ptr = im->rgb_data;
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
v = (int)(*ptr++);
v += (int)(*ptr++);
v += (int)(*ptr++);
v /= 3;
if (v < 0x10)
fprintf(f, "0%x", v);
else
fprintf(f, "%x", v);
}
fprintf(f, "\n");
}
}
fprintf(f, "\n");
fprintf(f, "showpage\n");
fprintf(f, "end\n");
fprintf(f, "origstate restore\n");
fprintf(f, "%%%%Trailer\n");
fclose(f);
return 1;
}
}
else if ((!strcasecmp(ext, "jpeg")) || (!strcasecmp(ext, "jpg")))
{
#ifdef HAVE_LIBJPEG
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW row_pointer[1];
int row_stride;
int y;
f = fopen(file, "wb");
if (f)
{
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, f);
cinfo.image_width = im->rgb_width;
cinfo.image_height = im->rgb_height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, (100 * info->quality) >> 8, TRUE);
jpeg_start_compress(&cinfo, TRUE);
row_stride = cinfo.image_width * 3;
while (cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = im->rgb_data + (cinfo.next_scanline * row_stride);
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
fclose(f);
return 1;
}
#endif
}
else if (!strcasecmp(ext, "png"))
{
#ifdef HAVE_LIBPNG
png_structp png_ptr;
png_infop info_ptr;
unsigned char *data, *ptr;
int x, y;
png_bytep row_ptr;
png_color_8 sig_bit;
f = fopen(file, "wb");
if (f)
{
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if (!png_ptr)
{
fclose(f);
return 0;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return 0;
}
if (setjmp(png_ptr->jmpbuf))
{
fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return 0;
}
png_init_io(png_ptr, f);
png_set_IHDR(png_ptr, info_ptr, im->rgb_width, im->rgb_height, 8,
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
sig_bit.red = 8;
sig_bit.green = 8;
sig_bit.blue = 8;
sig_bit.alpha = 8;
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
png_write_info(png_ptr, info_ptr);
png_set_shift(png_ptr, &sig_bit);
png_set_packing(png_ptr);
data = malloc(im->rgb_width * 4);
if (!data)
{
fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return 0;
}
for (y = 0; y < im->rgb_height; y++)
{
ptr = im->rgb_data + (y * im->rgb_width * 3);
for (x = 0; x < im->rgb_width; x++)
{
data[(x << 2) + 0] = *ptr++;
data[(x << 2) + 1] = *ptr++;
data[(x << 2) + 2] = *ptr++;
if ((data[(x << 2) + 0] == im->shape_color.r) &&
(data[(x << 2) + 1] == im->shape_color.g) &&
(data[(x << 2) + 2] == im->shape_color.b))
data[(x << 2) + 3] = 0;
else
data[(x << 2) + 3] = 255;
}
row_ptr = data;
png_write_rows(png_ptr, &row_ptr, 1);
}
free(data);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
fclose(f);
return 1;
}
#endif
}
else if ((!strcasecmp(ext, "tiff")) || (!strcasecmp(ext, "tif")))
{
#ifdef HAVE_LIBTIFF
TIFF *tif;
unsigned char *ptr, *data;
int x, y;
int w;
tif = TIFFOpen(file, "w");
if (tif)
{
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, im->rgb_width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, im->rgb_height);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
{
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
w = TIFFScanlineSize(tif);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, -1));
for (y = 0; y < im->rgb_height; y++)
{
data = im->rgb_data + (y * im->rgb_width * 3);
TIFFWriteScanline(tif, data, y, 0);
}
}
TIFFClose(tif);
return 1;
}
#endif
}
if (id->fallback)
{
f = open_helper("%C/convert pnm:- %s", file, "wb");
if (f)
{
if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height))
{
close_helper(f);
return 0;
}
if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f))
{
close_helper(f);
return 0;
}
if (close_helper(f))
return 0;
return 1;
}
if (!strcasecmp(ext, "jpeg"))
g_snprintf(cmd, sizeof(cmd), "%%H -quality %i -progressive -outfile %%s", 100 * info->quality / 256);
else if (!strcasecmp(ext, "jpg"))
g_snprintf(cmd, sizeof(cmd), "%%H -quality %i -progressive -outfile %%s", 100 * info->quality / 256);
else if (!strcasecmp(ext, "bmp"))
strcpy(cmd, "%Q %N/ppmtobmp >%s");
else if (!strcasecmp(ext, "gif"))
strcpy(cmd, "%Q %N/ppmtogif -interlace >%s");
else if (!strcasecmp(ext, "ilbm"))
strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress >%s");
else if (!strcasecmp(ext, "ilb"))
strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress >%s");
else if (!strcasecmp(ext, "iff"))
strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress >%s");
else if (!strcasecmp(ext, "icr"))
strcpy(cmd, "%N/ppmtoicr >%s");
else if (!strcasecmp(ext, "map"))
strcpy(cmd, "%N/ppmtomap >%s");
else if (!strcasecmp(ext, "mit"))
strcpy(cmd, "%N/ppmtomitsu -sharpness 4 >%s");
else if (!strcasecmp(ext, "mitsu"))
strcpy(cmd, "%N/ppmtomitsu -sharpness 4 >%s");
else if (!strcasecmp(ext, "pcx"))
strcpy(cmd, "%N/ppmtopcx -24bit -packed >%s");
else if (!strcasecmp(ext, "pgm"))
strcpy(cmd, "%N/ppmtopgm >%s");
else if (!strcasecmp(ext, "pi1"))
strcpy(cmd, "%N/ppmtopi1 >%s");
else if (!strcasecmp(ext, "pic"))
strcpy(cmd, "%Q %N/ppmtopict >%s");
else if (!strcasecmp(ext, "pict"))
strcpy(cmd, "%Q %N/ppmtopict >%s");
else if (!strcasecmp(ext, "pj"))
strcpy(cmd, "%N/ppmtopj >%s");
else if (!strcasecmp(ext, "pjxl"))
strcpy(cmd, "%N/ppmtopjxl >%s");
else if (!strcasecmp(ext, "puz"))
strcpy(cmd, "%N/ppmtopuzz >%s");
else if (!strcasecmp(ext, "puzz"))
strcpy(cmd, "%N/ppmtopuzz >%s");
else if (!strcasecmp(ext, "rgb3"))
strcpy(cmd, "%N/ppmtorgb3 >%s");
else if (!strcasecmp(ext, "six"))
strcpy(cmd, "%N/ppmtosixel >%s");
else if (!strcasecmp(ext, "sixel"))
strcpy(cmd, "%N/ppmtosizel >%s");
else if (!strcasecmp(ext, "tga"))
strcpy(cmd, "%N/ppmtotga -rgb >%s");
else if (!strcasecmp(ext, "targa"))
strcpy(cmd, "%N/ppmtotga -rgb >%s");
else if (!strcasecmp(ext, "uil"))
strcpy(cmd, "%N/ppmtouil >%s");
else if (!strcasecmp(ext, "xpm"))
strcpy(cmd, "%Q %N/ppmtoxpm >%s");
else if (!strcasecmp(ext, "yuv"))
strcpy(cmd, "%N/ppmtoyuv >%s");
else if (!strcasecmp(ext, "png"))
strcpy(cmd, "%N/pnmtopng >%s");
else if (!strcasecmp(ext, "ps"))
strcpy(cmd, "%N/pnmtops -center -scale 100 >%s");
else if (!strcasecmp(ext, "rast"))
strcpy(cmd, "%N/pnmtorast -rle >%s");
else if (!strcasecmp(ext, "ras"))
strcpy(cmd, "%N/pnmtorast -rle >%s");
else if (!strcasecmp(ext, "sgi"))
strcpy(cmd, "%N/pnmtosgi >%s");
else if (!strcasecmp(ext, "sir"))
strcpy(cmd, "%N/pnmtosir >%s");
else if (!strcasecmp(ext, "tif"))
strcpy(cmd, "%N/pnmtotiff -lzw >%s");
else if (!strcasecmp(ext, "tiff"))
strcpy(cmd, "%N/pnmtotiff -lzw >%s");
else if (!strcasecmp(ext, "xwd"))
strcpy(cmd, "%N/pnmtoxwd >%s");
else
ext = "";
if (ext[0])
{
f = open_helper(cmd, file, "wb");
if (f)
{
if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height))
{
close_helper(f);
return 0;
}
if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f))
{
close_helper(f);
return 0;
}
if (close_helper(f))
return 0;
return 1;
}
}
}
return 0;
}

1518
src/gdk_imlib/utils.c Normal file

File diff suppressed because it is too large Load Diff

303
src/generic/choicdgg.cpp Normal file
View File

@@ -0,0 +1,303 @@
/////////////////////////////////////////////////////////////////////////////
// Name: choicesg.cpp
// Purpose: Choice dialogs
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "choicdgg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/listbox.h"
#include "wx/button.h"
#include "wx/stattext.h"
#include "wx/layout.h"
#include "wx/intl.h"
#endif
#include "wx/generic/choicdgg.h"
extern void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer);
wxString wxGetSingleChoice( const wxString& message, const wxString& caption, const int n,
const wxString *choices, wxWindow *parent,
const int WXUNUSED(x), const int WXUNUSED(y), const bool WXUNUSED(centre),
const int WXUNUSED(width), const int WXUNUSED(height) )
{
wxSingleChoiceDialog dialog(parent, message, caption, n, choices);
if ( dialog.ShowModal() == wxID_OK )
{
return dialog.GetStringSelection();
}
else
return "";
}
// Overloaded for backward compatibility
wxString wxGetSingleChoice( const wxString& message, const wxString& caption, const int n,
char *choices[], wxWindow *parent,
const int x, const int y, const bool centre,
const int width, const int height )
{
wxString *strings = new wxString[n];
int i;
for ( i = 0; i < n; i++)
{
strings[i] = choices[i];
}
wxString ans(wxGetSingleChoice(message, caption, n, (const wxString *)strings, parent,
x, y, centre, width, height));
delete[] strings;
return ans;
}
int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, const int n,
const wxString *choices, wxWindow *parent,
const int WXUNUSED(x), const int WXUNUSED(y), const bool WXUNUSED(centre),
const int WXUNUSED(width), const int WXUNUSED(height) )
{
wxSingleChoiceDialog dialog(parent, message, caption, n, choices);
if ( dialog.ShowModal() == wxID_OK )
{
return dialog.GetSelection();
}
else
return -1;
}
// Overloaded for backward compatibility
int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, const int n,
char *choices[], wxWindow *parent,
const int x, const int y, const bool centre,
const int width, const int height )
{
wxString *strings = new wxString[n];
int i;
for ( i = 0; i < n; i++)
{
strings[i] = choices[i];
}
int ans = wxGetSingleChoiceIndex(message, caption, n, (const wxString *)strings, parent,
x, y, centre, width, height);
delete[] strings;
return ans;
}
char *wxGetSingleChoiceData( const wxString& message, const wxString& caption, const int n,
const wxString *choices, char **client_data, wxWindow *parent,
const int WXUNUSED(x), const int WXUNUSED(y), const bool WXUNUSED(centre),
const int WXUNUSED(width), const int WXUNUSED(height) )
{
wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data);
if ( dialog.ShowModal() == wxID_OK )
{
return dialog.GetSelectionClientData();
}
else
return NULL;
}
// Overloaded for backward compatibility
char *wxGetSingleChoiceData( const wxString& message, const wxString& caption, const int n,
char *choices[], char **client_data, wxWindow *parent,
const int x, const int y, const bool centre,
const int width, const int height )
{
wxString *strings = new wxString[n];
int i;
for ( i = 0; i < n; i++)
{
strings[i] = choices[i];
}
char *data = wxGetSingleChoiceData(message, caption, n, (const wxString *)strings, client_data, parent,
x, y, centre, width, height);
delete[] strings;
return data;
}
/* Multiple choice dialog contributed by Robert Cowell
*
The new data passed are in the "int nsel" and "int * selection"
The idea is to make a multiple selection from list of strings.
The returned value is the total number selected. initialily there
are nsel selected, with indices stored in
selection[0],...,selection[nsel-1] which appear highlighted to
begin with. On exit with value i
selection[0..i-1] contains the indices of the selected items.
(Some prior selectecions might be deselected.)
Thus selection must be as big as choices, in case all items are
selected.
*/
/*
int wxGetMultipleChoice(const wxString& message, const wxString& caption,
const int n, const wxString *choices,
const int nsel, int * selection,
wxWindow *parent , const int x , const int y, const bool centre,
const int width, const int height)
{
return -1;
}
*/
// wxSingleChoiceDialog
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxSingleChoiceDialog, wxDialog)
EVT_BUTTON(wxID_OK, wxSingleChoiceDialog::OnOK)
END_EVENT_TABLE()
IMPLEMENT_CLASS(wxSingleChoiceDialog, wxDialog)
#endif
wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent, const wxString& message, const wxString& caption,
const int n, const wxString *choices, char **clientData, long style, const wxPoint& pos):
wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
Create(parent, message, caption, n, choices, clientData, style);
}
wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent, const wxString& message, const wxString& caption,
const wxStringList& choices, char **clientData, long style, const wxPoint& pos):
wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
Create(parent, message, caption, choices, clientData, style);
}
bool wxSingleChoiceDialog::Create(wxWindow *parent, const wxString& message, const wxString& caption,
const wxStringList& choices, char **clientData, long style, const wxPoint& pos)
{
wxString *strings = new wxString[choices.Number()];
int i;
for ( i = 0; i < choices.Number(); i++)
{
strings[i] = (char *)choices.Nth(i)->Data();
}
bool ans = Create(parent, message, caption, choices.Number(), strings, clientData, style, pos);
delete[] strings;
return ans;
}
bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& message,
const wxString& WXUNUSED(caption), const int n,
const wxString *choices, char **clientData, long style,
const wxPoint& WXUNUSED(pos) )
{
m_dialogStyle = style;
m_selection = 0;
m_stringSelection = "";
m_clientData = NULL;
wxBeginBusyCursor();
wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
topSizer->SetBorder(10, 10);
wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
messageSizer->SetName("messageSizer");
// bool centre = ((style & wxCENTRE) == wxCENTRE);
wxList messageList;
wxSplitMessage2(message, &messageList, this, messageSizer);
// Insert a spacer
wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 10);
wxListBox *listBox = new wxListBox(this, wxID_LISTBOX, wxPoint(-1, -1), wxSize(240, 160),
n, choices);
if ( clientData )
{
int i;
for ( i = 0; i < n; i++)
{
listBox->SetClientData(i, clientData[i]);
}
}
wxRowColSizer *listBoxSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
listBoxSizer->AddSizerChild(listBox);
listBoxSizer->SetName("listBoxSizer");
// Create constraints for the text sizer
wxLayoutConstraints *textC = new wxLayoutConstraints;
textC->left.SameAs (messageSizer, wxLeft);
textC->top.Below (spacingSizer);
listBoxSizer->SetConstraints(textC);
// Insert another spacer
wxSpacingSizer *spacingSizer2 = new wxSpacingSizer(topSizer, wxBelow, listBoxSizer, 10);
spacingSizer->SetName("spacingSizer2");
// Insert a sizer for the buttons
wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
buttonSizer->SetName("buttonSizer");
// Specify constraints for the button sizer
wxLayoutConstraints *c = new wxLayoutConstraints;
c->width.AsIs ();
c->height.AsIs ();
c->top.Below (spacingSizer2);
c->centreX.SameAs (listBoxSizer, wxCentreX);
buttonSizer->SetConstraints(c);
wxButton *ok = NULL;
wxButton *cancel = NULL;
if (style & wxOK) {
ok = new wxButton(this, wxID_OK, _("OK"));
buttonSizer->AddSizerChild(ok);
}
if (style & wxCANCEL) {
cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
buttonSizer->AddSizerChild(cancel);
}
if (ok)
{
ok->SetDefault();
ok->SetFocus();
}
Layout();
Centre(wxBOTH);
wxEndBusyCursor();
return TRUE;
}
void wxSingleChoiceDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
wxListBox *listBox = (wxListBox *)FindWindow(wxID_LISTBOX);
if ( listBox )
{
m_selection = listBox->GetSelection();
m_stringSelection = listBox->GetStringSelection();
m_clientData = listBox->GetClientData(m_selection);
}
EndModal(wxID_OK);
}

487
src/generic/colrdlgg.cpp Normal file
View File

@@ -0,0 +1,487 @@
/////////////////////////////////////////////////////////////////////////////
// Name: colrdlgg.cpp
// Purpose: Choice dialogs
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "colrdlgg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include <stdio.h>
#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/dialog.h"
#include "wx/listbox.h"
#include "wx/button.h"
#include "wx/stattext.h"
#include "wx/layout.h"
#include "wx/dcclient.h"
#include "wx/slider.h"
#endif
#include "wx/generic/colrdlgg.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxGenericColourDialog, wxDialog)
BEGIN_EVENT_TABLE(wxGenericColourDialog, wxDialog)
EVT_BUTTON(wxID_ADD_CUSTOM, wxGenericColourDialog::OnAddCustom)
EVT_SLIDER(wxID_RED_SLIDER, wxGenericColourDialog::OnRedSlider)
EVT_SLIDER(wxID_GREEN_SLIDER, wxGenericColourDialog::OnGreenSlider)
EVT_SLIDER(wxID_BLUE_SLIDER, wxGenericColourDialog::OnBlueSlider)
EVT_PAINT(wxGenericColourDialog::OnPaint)
EVT_MOUSE_EVENTS(wxGenericColourDialog::OnMouseEvent)
END_EVENT_TABLE()
#endif
/*
* Generic wxColourDialog
*/
#define NUM_COLS 48
static wxString wxColourDialogNames[NUM_COLS]={"ORANGE",
"GOLDENROD",
"WHEAT",
"SPRING GREEN",
"SKY BLUE",
"SLATE BLUE",
"MEDIUM VIOLET RED",
"PURPLE",
"RED",
"YELLOW",
"MEDIUM SPRING GREEN",
"PALE GREEN",
"CYAN",
"LIGHT STEEL BLUE",
"ORCHID",
"LIGHT MAGENTA",
"BROWN",
"YELLOW",
"GREEN",
"CADET BLUE",
"MEDIUM BLUE",
"MAGENTA",
"MAROON",
"ORANGE RED",
"FIREBRICK",
"CORAL",
"FOREST GREEN",
"AQUARAMINE",
"BLUE",
"NAVY",
"THISTLE",
"MEDIUM VIOLET RED",
"INDIAN RED",
"GOLD",
"MEDIUM SEA GREEN",
"MEDIUM BLUE",
"MIDNIGHT BLUE",
"GREY",
"PURPLE",
"KHAKI",
"BLACK",
"MEDIUM FOREST GREEN",
"KHAKI",
"DARK GREY",
"SEA GREEN",
"LIGHT GREY",
"MEDIUM SLATE BLUE",
"WHITE"
};
wxGenericColourDialog::wxGenericColourDialog(void)
{
dialogParent = NULL;
whichKind = 1;
colourSelection = 0;
}
wxGenericColourDialog::wxGenericColourDialog(wxWindow *parent, wxColourData *data):
wxDialog(parent, -1, "Colour", wxPoint(0, 0), wxSize(900, 900), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
whichKind = 1;
colourSelection = 0;
Create(parent, data);
}
wxGenericColourDialog::~wxGenericColourDialog(void)
{
}
bool wxGenericColourDialog::OnClose(void)
{
Show(FALSE);
return FALSE;
}
bool wxGenericColourDialog::Create(wxWindow *parent, wxColourData *data)
{
dialogParent = parent;
if (data)
colourData = *data;
InitializeColours();
CalculateMeasurements();
CreateWidgets();
return TRUE;
}
int wxGenericColourDialog::ShowModal(void)
{
return wxDialog::ShowModal();
}
// Internal functions
void wxGenericColourDialog::OnMouseEvent(wxMouseEvent& event)
{
if (event.ButtonDown(1))
{
int x = (int)event.GetX();
int y = (int)event.GetY();
if ((x >= standardColoursRect.x && x <= (standardColoursRect.x + standardColoursRect.width)) &&
(y >= standardColoursRect.y && y <= (standardColoursRect.y + standardColoursRect.height)))
{
int selX = (int)(x - standardColoursRect.x)/(smallRectangleSize.x + gridSpacing);
int selY = (int)(y - standardColoursRect.y)/(smallRectangleSize.y + gridSpacing);
int ptr = (int)(selX + selY*8);
OnBasicColourClick(ptr);
}
else if ((x >= customColoursRect.x && x <= (customColoursRect.x + customColoursRect.width)) &&
(y >= customColoursRect.y && y <= (customColoursRect.y + customColoursRect.height)))
{
int selX = (int)(x - customColoursRect.x)/(smallRectangleSize.x + gridSpacing);
int selY = (int)(y - customColoursRect.y)/(smallRectangleSize.y + gridSpacing);
int ptr = (int)(selX + selY*8);
OnCustomColourClick(ptr);
}
}
}
void wxGenericColourDialog::OnPaint(wxPaintEvent& event)
{
wxDialog::OnPaint(event);
wxPaintDC dc(this);
PaintBasicColours(dc);
PaintCustomColours(dc);
PaintCustomColour(dc);
PaintHighlight(dc, TRUE);
}
void wxGenericColourDialog::CalculateMeasurements(void)
{
smallRectangleSize.x = 18;
smallRectangleSize.y = 14;
customRectangleSize.x = 40;
customRectangleSize.y = 40;
gridSpacing = 6;
sectionSpacing = 15;
standardColoursRect.x = 10;
standardColoursRect.y = 15;
standardColoursRect.width = (8*smallRectangleSize.x) + (7*gridSpacing);
standardColoursRect.height = (6*smallRectangleSize.y) + (5*gridSpacing);
customColoursRect.x = standardColoursRect.x;
customColoursRect.y = standardColoursRect.y + standardColoursRect.height + 20;
customColoursRect.width = (8*smallRectangleSize.x) + (7*gridSpacing);
customColoursRect.height = (2*smallRectangleSize.y) + (1*gridSpacing);
singleCustomColourRect.x = customColoursRect.width + customColoursRect.x + sectionSpacing;
singleCustomColourRect.y = 80;
singleCustomColourRect.width = customRectangleSize.x;
singleCustomColourRect.height = customRectangleSize.y;
okButtonX = 10;
customButtonX = singleCustomColourRect.x ;
buttonY = customColoursRect.y + customColoursRect.height + 10;
}
void wxGenericColourDialog::CreateWidgets(void)
{
wxBeginBusyCursor();
wxButton *okButton = new wxButton(this, wxID_OK, "OK", wxPoint(okButtonX, buttonY));
int bw, bh;
okButton->GetSize(&bw, &bh);
(void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(okButtonX + bw + 10, buttonY));
(void) new wxButton(this, wxID_ADD_CUSTOM, "Add to custom colours",
wxPoint(customButtonX, buttonY));
int sliderX = singleCustomColourRect.x + singleCustomColourRect.width + sectionSpacing;
#ifdef __X__
int sliderSpacing = 75;
int sliderHeight = 160;
#else
int sliderSpacing = 45;
int sliderHeight = 160;
#endif
redSlider = new wxSlider(this, wxID_RED_SLIDER, 0, 0, 255,
wxPoint(sliderX, 10), wxSize(-1, sliderHeight), wxVERTICAL|wxSL_LABELS);
greenSlider = new wxSlider(this, wxID_GREEN_SLIDER, 0, 0, 255,
wxPoint(sliderX + sliderSpacing, 10), wxSize(-1, sliderHeight), wxVERTICAL|wxSL_LABELS);
blueSlider = new wxSlider(this, wxID_BLUE_SLIDER, 0, 0, 255,
wxPoint(sliderX + 2*sliderSpacing, 10), wxSize(-1, sliderHeight), wxVERTICAL|wxSL_LABELS);
SetClientSize(sliderX + 3*sliderSpacing, buttonY + 30);
okButton->SetDefault();
Centre(wxBOTH);
wxEndBusyCursor();
}
void wxGenericColourDialog::InitializeColours(void)
{
int i;
for (i = 0; i < 48; i++)
{
wxColour *col = wxTheColourDatabase->FindColour(wxColourDialogNames[i]);
if (col)
standardColours[i].Set(col->Red(), col->Green(), col->Blue());
else
standardColours[i].Set(0, 0, 0);
}
for (i = 0; i < 16; i++)
customColours[i] =
/*
#ifndef __VMS__
(wxColour&)
#endif
*/
colourData.GetCustomColour(i);
singleCustomColour.Set(0, 0, 0);
}
void wxGenericColourDialog::PaintBasicColours(wxDC& dc)
{
dc.BeginDrawing();
int i;
for (i = 0; i < 6; i++)
{
int j;
for (j = 0; j < 8; j++)
{
int ptr = i*8 + j;
int x = (j*(smallRectangleSize.x+gridSpacing) + standardColoursRect.x);
int y = (i*(smallRectangleSize.y+gridSpacing) + standardColoursRect.y);
dc.SetPen(*wxBLACK_PEN);
wxBrush brush(standardColours[ptr], wxSOLID);
dc.SetBrush(brush);
dc.DrawRectangle( x, y, smallRectangleSize.x, smallRectangleSize.y);
}
}
dc.EndDrawing();
}
void wxGenericColourDialog::PaintCustomColours(wxDC& dc)
{
dc.BeginDrawing();
int i;
for (i = 0; i < 2; i++)
{
int j;
for (j = 0; j < 8; j++)
{
int ptr = i*8 + j;
int x = (j*(smallRectangleSize.x+gridSpacing)) + customColoursRect.x;
int y = (i*(smallRectangleSize.y+gridSpacing)) + customColoursRect.y;
dc.SetPen(*wxBLACK_PEN);
wxBrush brush(customColours[ptr], wxSOLID);
dc.SetBrush(brush);
dc.DrawRectangle( x, y, smallRectangleSize.x, smallRectangleSize.y);
}
}
dc.EndDrawing();
}
void wxGenericColourDialog::PaintHighlight(wxDC& dc, bool draw)
{
dc.BeginDrawing();
// Number of pixels bigger than the standard rectangle size
// for drawing a highlight
int deltaX = 2;
int deltaY = 2;
if (whichKind == 1)
{
// Standard colours
int y = (int)(colourSelection / 8);
int x = (int)(colourSelection - (y*8));
x = (x*(smallRectangleSize.x + gridSpacing) + standardColoursRect.x) - deltaX;
y = (y*(smallRectangleSize.y + gridSpacing) + standardColoursRect.y) - deltaY;
if (draw)
dc.SetPen(*wxBLACK_PEN);
else
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle( x, y, (smallRectangleSize.x + (2*deltaX)), (smallRectangleSize.y + (2*deltaY)));
}
else
{
// User-defined colours
int y = (int)(colourSelection / 8);
int x = (int)(colourSelection - (y*8));
x = (x*(smallRectangleSize.x + gridSpacing) + customColoursRect.x) - deltaX;
y = (y*(smallRectangleSize.y + gridSpacing) + customColoursRect.y) - deltaY;
if (draw)
dc.SetPen(*wxBLACK_PEN);
else
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle( x, y, (smallRectangleSize.x + (2*deltaX)), (smallRectangleSize.y + (2*deltaY)));
}
dc.EndDrawing();
}
void wxGenericColourDialog::PaintCustomColour(wxDC& dc)
{
dc.BeginDrawing();
dc.SetPen(*wxBLACK_PEN);
wxBrush *brush = new wxBrush(singleCustomColour, wxSOLID);
dc.SetBrush(*brush);
dc.DrawRectangle( singleCustomColourRect.x, singleCustomColourRect.y,
customRectangleSize.x, customRectangleSize.y);
dc.SetBrush(wxNullBrush);
delete brush;
dc.EndDrawing();
}
void wxGenericColourDialog::OnBasicColourClick(int which)
{
wxClientDC dc(this);
PaintHighlight(dc, FALSE);
whichKind = 1;
colourSelection = which;
colourData.SetColour(standardColours[colourSelection]);
PaintHighlight(dc, TRUE);
}
void wxGenericColourDialog::OnCustomColourClick(int which)
{
wxClientDC dc(this);
PaintHighlight(dc, FALSE);
whichKind = 2;
colourSelection = which;
colourData.SetColour(customColours[colourSelection]);
PaintHighlight(dc, TRUE);
}
/*
void wxGenericColourDialog::OnOk(void)
{
Show(FALSE);
}
void wxGenericColourDialog::OnCancel(void)
{
colourDialogCancelled = TRUE;
Show(FALSE);
}
*/
void wxGenericColourDialog::OnAddCustom(wxCommandEvent& WXUNUSED(event))
{
wxClientDC dc(this);
if (whichKind != 2)
{
PaintHighlight(dc, FALSE);
whichKind = 2;
colourSelection = 0;
PaintHighlight(dc, TRUE);
}
customColours[colourSelection].Set(singleCustomColour.Red(), singleCustomColour.Green(), singleCustomColour.Blue());
colourData.SetColour(customColours[colourSelection]);
colourData.SetCustomColour(colourSelection, customColours[colourSelection]);
PaintCustomColours(dc);
}
void wxGenericColourDialog::OnRedSlider(wxCommandEvent& WXUNUSED(event))
{
if (!redSlider)
return;
wxClientDC dc(this);
singleCustomColour.Set(redSlider->GetValue(), singleCustomColour.Green(), singleCustomColour.Blue());
PaintCustomColour(dc);
}
void wxGenericColourDialog::OnGreenSlider(wxCommandEvent& WXUNUSED(event))
{
if (!greenSlider)
return;
wxClientDC dc(this);
singleCustomColour.Set(singleCustomColour.Red(), greenSlider->GetValue(), singleCustomColour.Blue());
PaintCustomColour(dc);
}
void wxGenericColourDialog::OnBlueSlider(wxCommandEvent& WXUNUSED(event))
{
if (!blueSlider)
return;
wxClientDC dc(this);
singleCustomColour.Set(singleCustomColour.Red(), singleCustomColour.Green(), blueSlider->GetValue());
PaintCustomColour(dc);
}

425
src/generic/fontdlgg.cpp Normal file
View File

@@ -0,0 +1,425 @@
/////////////////////////////////////////////////////////////////////////////
// Name: fontdlgg.cpp
// Purpose: Generic font dialog
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "fontdlgg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/listbox.h"
#include "wx/button.h"
#include "wx/stattext.h"
#include "wx/layout.h"
#include "wx/dcclient.h"
#include "wx/choice.h"
#include "wx/checkbox.h"
#endif
#include <string.h>
#include <stdlib.h>
#include "wx/cmndata.h"
#include "wx/generic/fontdlgg.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxGenericFontDialog, wxDialog)
BEGIN_EVENT_TABLE(wxGenericFontDialog, wxDialog)
EVT_CHECKBOX(wxID_FONT_UNDERLINE, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_STYLE, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_WEIGHT, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_FAMILY, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_COLOUR, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeFont)
EVT_PAINT(wxGenericFontDialog::OnPaint)
END_EVENT_TABLE()
#endif
#define NUM_COLS 48
static wxString wxColourDialogNames[NUM_COLS]={"ORANGE",
"GOLDENROD",
"WHEAT",
"SPRING GREEN",
"SKY BLUE",
"SLATE BLUE",
"MEDIUM VIOLET RED",
"PURPLE",
"RED",
"YELLOW",
"MEDIUM SPRING GREEN",
"PALE GREEN",
"CYAN",
"LIGHT STEEL BLUE",
"ORCHID",
"LIGHT MAGENTA",
"BROWN",
"YELLOW",
"GREEN",
"CADET BLUE",
"MEDIUM BLUE",
"MAGENTA",
"MAROON",
"ORANGE RED",
"FIREBRICK",
"CORAL",
"FOREST GREEN",
"AQUARAMINE",
"BLUE",
"NAVY",
"THISTLE",
"MEDIUM VIOLET RED",
"INDIAN RED",
"GOLD",
"MEDIUM SEA GREEN",
"MEDIUM BLUE",
"MIDNIGHT BLUE",
"GREY",
"PURPLE",
"KHAKI",
"BLACK",
"MEDIUM FOREST GREEN",
"KHAKI",
"DARK GREY",
"SEA GREEN",
"LIGHT GREY",
"MEDIUM SLATE BLUE",
"WHITE"
};
/*
* Generic wxFontDialog
*/
wxGenericFontDialog::wxGenericFontDialog(void)
{
dialogParent = NULL;
}
wxGenericFontDialog::wxGenericFontDialog(wxWindow *parent, wxFontData *data):
wxDialog(parent, -1, "Font", wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
Create(parent, data);
}
wxGenericFontDialog::~wxGenericFontDialog(void)
{
}
bool wxGenericFontDialog::OnClose(void)
{
Show(FALSE);
return FALSE;
}
bool wxGenericFontDialog::Create(wxWindow *parent, wxFontData *data)
{
dialogParent = parent;
if (data)
fontData = *data;
InitializeFont();
CreateWidgets();
return TRUE;
}
int wxGenericFontDialog::ShowModal(void)
{
int ret = wxDialog::ShowModal();
if (ret != wxID_CANCEL)
{
fontData.chosenFont = dialogFont;
}
return ret;
}
void wxGenericFontDialog::OnPaint(wxPaintEvent& event)
{
wxDialog::OnPaint(event);
wxPaintDC dc(this);
PaintFontBackground(dc);
PaintFont(dc);
}
/*
static void wxGenericChangeFontText(wxTextCtrl& text, wxCommandEvent& event)
{
if (event.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND)
{
wxGenericFontDialog *dialog = (wxGenericFontDialog *)text.GetParent();
dialog->OnChangeFont();
}
}
*/
void wxGenericFontDialog::CreateWidgets(void)
{
wxBeginBusyCursor();
fontRect.x = 5;
#ifdef __X__
fontRect.y = 125;
#else
fontRect.y = 115;
#endif
fontRect.width = 350;
fontRect.height = 100;
/*
static char *families[] = { "Roman", "Decorative", "Modern", "Script", "Swiss" };
static char *styles[] = { "Normal", "Italic", "Slant" };
static char *weights[] = { "Normal", "Light", "Bold" };
*/
static wxString families[] = { "Roman", "Decorative", "Modern", "Script", "Swiss" };
static wxString styles[] = { "Normal", "Italic", "Slant" };
static wxString weights[] = { "Normal", "Light", "Bold" };
int x=-1;
int y=40;
familyChoice = new wxChoice(this, wxID_FONT_FAMILY, wxPoint(10, 10), wxSize(120, -1), 5, families);
styleChoice = new wxChoice(this, wxID_FONT_STYLE, wxPoint(140, 10), wxSize(120, -1), 3, styles);
weightChoice = new wxChoice(this, wxID_FONT_WEIGHT, wxPoint(270, 10), wxSize(120, -1), 3, weights);
colourChoice = new wxChoice(this, wxID_FONT_COLOUR, wxPoint(10, 40), wxSize(190, -1), NUM_COLS, wxColourDialogNames);
#ifdef __MOTIF__
// We want the pointSizeText to line up on the y axis with the colourChoice
colourChoice->GetPosition(&fontRect.x, &y); //NL mod
y+=3; //NL mod
#endif
wxString pointSizes[40];
int i;
for ( i = 0; i < 40; i++)
{
char buf[5];
sprintf(buf, "%d", i + 1);
pointSizes[i] = buf;
}
pointSizeChoice = new wxChoice(this, wxID_FONT_SIZE, wxPoint(210, y), wxSize(50, -1), 40, pointSizes);
underLineCheckBox = new wxCheckBox(this, wxID_FONT_UNDERLINE, "Underline", wxPoint(280, y));
int rectY;
pointSizeChoice->GetPosition(&x, &rectY); //NL mod
fontRect.y = rectY;
pointSizeChoice->GetSize(&x, &y); //NL mod
// Calculate the position of the bottom of the pointSizeChoice, and place
// the fontRect there (+5 for a nice gap)
fontRect.y+=y+5; //NL mod
int by = (fontRect.y + fontRect.height + 5);
wxButton *okButton = new wxButton(this, wxID_OK, "OK", wxPoint(5, by));
(void) new wxButton(this, wxID_OK, "Cancel", wxPoint(50, by));
familyChoice->SetStringSelection(wxFontFamilyIntToString(dialogFont.GetFamily()));
styleChoice->SetStringSelection(wxFontStyleIntToString(dialogFont.GetStyle()));
weightChoice->SetStringSelection(wxFontWeightIntToString(dialogFont.GetWeight()));
wxString name(wxTheColourDatabase->FindName(fontData.fontColour));
colourChoice->SetStringSelection(name);
underLineCheckBox->SetValue(dialogFont.GetUnderlined());
pointSizeChoice->SetSelection(dialogFont.GetPointSize());
okButton->SetDefault();
SetClientSize(400, by + 30);
Centre(wxBOTH);
wxEndBusyCursor();
}
void wxGenericFontDialog::InitializeFont(void)
{
int fontFamily = wxSWISS;
int fontWeight = wxNORMAL;
int fontStyle = wxNORMAL;
int fontSize = 12;
int fontUnderline = FALSE;
if (fontData.initialFont.Ok())
{
fontFamily = fontData.initialFont.GetFamily();
fontWeight = fontData.initialFont.GetWeight();
fontStyle = fontData.initialFont.GetStyle();
fontSize = fontData.initialFont.GetPointSize();
fontUnderline = fontData.initialFont.GetUnderlined();
}
dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
}
void wxGenericFontDialog::PaintFontBackground(wxDC& dc)
{
dc.BeginDrawing();
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle( fontRect.x, fontRect.y, fontRect.width, fontRect.height);
dc.EndDrawing();
}
void wxGenericFontDialog::PaintFont(wxDC& dc)
{
dc.BeginDrawing();
if (dialogFont.Ok())
{
dc.SetFont(dialogFont);
// Calculate vertical centre
long w, h;
dc.GetTextExtent("X", &w, &h);
float cx = (float)(fontRect.x + 10);
float cy = (float)(fontRect.y + (fontRect.height/2.0) - (h/2.0));
dc.SetTextForeground(fontData.fontColour);
dc.SetClippingRegion( fontRect.x, fontRect.y, (long)(fontRect.width-2.0), (long)(fontRect.height-2.0));
dc.DrawText("ABCDEFGabcdefg12345", (long)cx, (long)cy);
dc.DestroyClippingRegion();
dc.SetFont(wxNullFont);
}
dc.EndDrawing();
}
void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
{
int fontFamily = wxFontFamilyStringToInt(WXSTRINGCAST familyChoice->GetStringSelection());
int fontWeight = wxFontWeightStringToInt(WXSTRINGCAST weightChoice->GetStringSelection());
int fontStyle = wxFontStyleStringToInt(WXSTRINGCAST styleChoice->GetStringSelection());
int fontSize = atoi(pointSizeChoice->GetStringSelection());
int fontUnderline = underLineCheckBox->GetValue();
dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
if (colourChoice->GetStringSelection() != "")
{
wxColour *col = wxTheColourDatabase->FindColour(colourChoice->GetStringSelection());
if (col)
{
fontData.fontColour = *col;
}
}
wxClientDC dc(this);
PaintFontBackground(dc);
PaintFont(dc);
}
char *wxFontWeightIntToString(int weight)
{
switch (weight)
{
case wxLIGHT:
return "Light";
case wxBOLD:
return "Bold";
case wxNORMAL:
default:
return "Normal";
}
return "Normal";
}
char *wxFontStyleIntToString(int style)
{
switch (style)
{
case wxITALIC:
return "Italic";
case wxSLANT:
return "Slant";
case wxNORMAL:
default:
return "Normal";
}
return "Normal";
}
char *wxFontFamilyIntToString(int family)
{
switch (family)
{
case wxROMAN:
return "Roman";
case wxDECORATIVE:
return "Decorative";
case wxMODERN:
return "Modern";
case wxSCRIPT:
return "Script";
case wxSWISS:
default:
return "Swiss";
}
return "Swiss";
}
int wxFontFamilyStringToInt(char *family)
{
if (!family)
return wxSWISS;
if (strcmp(family, "Roman") == 0)
return wxROMAN;
else if (strcmp(family, "Decorative") == 0)
return wxDECORATIVE;
else if (strcmp(family, "Modern") == 0)
return wxMODERN;
else if (strcmp(family, "Script") == 0)
return wxSCRIPT;
else return wxSWISS;
}
int wxFontStyleStringToInt(char *style)
{
if (!style)
return wxNORMAL;
if (strcmp(style, "Italic") == 0)
return wxITALIC;
else if (strcmp(style, "Slant") == 0)
return wxSLANT;
else
return wxNORMAL;
}
int wxFontWeightStringToInt(char *weight)
{
if (!weight)
return wxNORMAL;
if (strcmp(weight, "Bold") == 0)
return wxBOLD;
else if (strcmp(weight, "Light") == 0)
return wxLIGHT;
else
return wxNORMAL;
}

2365
src/generic/gridg.cpp Normal file

File diff suppressed because it is too large Load Diff

257
src/generic/helpxlp.cpp Normal file
View File

@@ -0,0 +1,257 @@
/////////////////////////////////////////////////////////////////////////////
// Name: helpxlp.cpp
// Purpose: Help system: wxHelp implementation
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "helpxlp.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#endif
#include "wx/generic/helpxlp.h"
#if USE_HELP
#include <time.h>
#ifdef __X__
#include <netdb.h>
#ifdef SUN_CC
#include <sysent.h>
#endif // SUN_CC
#ifdef ____HPUX__
#include <sys/unistd.h>
#endif // ____HPUX__
#endif // __X__
#include <string.h>
// Timeout in seconds
#define WX_HELP_TIMEOUT 15 /* was 30 */
// MAX path length
#define _MAXPATHLEN 500
// MAX length of Help descriptor
#define _MAX_HELP_LEN 500
#include "wx/generic/helpxlp.h"
#if !USE_SHARED_LIBRARY
#ifdef __WINDOWS__
IMPLEMENT_CLASS(wxXLPHelpClient, wxDDEClient)
IMPLEMENT_CLASS(wxXLPHelpConnection, wxDDEConnection)
#else
IMPLEMENT_CLASS(wxXLPHelpClient, wxTCPClient)
IMPLEMENT_CLASS(wxXLPHelpConnection, wxTCPConnection)
#endif
IMPLEMENT_CLASS(wxXLPHelpController, wxHelpControllerBase)
#endif
wxXLPHelpController::wxXLPHelpController(void):
helpClient(this)
{
helpFile = ""; helpServer = -1; helpHost = "";
helpRunning = FALSE; helpConnection = NULL;
}
wxXLPHelpController::~wxXLPHelpController(void)
{
}
bool wxXLPHelpController::Initialize(const wxString& filename, int server)
{
#ifdef __X__
char host_buf[255];
if (wxGetHostName(host_buf, sizeof(host_buf)))
helpHost = host_buf;
else helpHost = "";
#endif
helpFile = filename;
helpServer = server;
wxIPCInitialize();
return TRUE;
}
bool wxXLPHelpController::LoadFile(const wxString& file)
{
helpFile = file;
if (!helpRunning)
{
if (!Run())
return FALSE;
}
char buf[_MAX_HELP_LEN];
sprintf(buf, "f %s", (const char*) file);
if (helpConnection)
return helpConnection->Execute(buf);
else return FALSE;
}
bool wxXLPHelpController::DisplayContents(void)
{
if (!helpRunning)
{
if (!Run())
return FALSE;
}
if (helpConnection)
return helpConnection->Execute("s -1");
else
return FALSE;
}
bool wxXLPHelpController::DisplaySection(int section)
{
if (!helpRunning)
{
if (!Run())
return FALSE;
}
char buf[_MAX_HELP_LEN];
sprintf(buf, "s %d", section);
if (helpConnection)
return helpConnection->Execute(buf);
else return FALSE;
}
bool wxXLPHelpController::DisplayBlock(long block)
{
if (!helpRunning)
{
if (!Run())
return FALSE;
}
char buf[_MAX_HELP_LEN];
sprintf(buf, "b %ld", block);
if (helpConnection)
return helpConnection->Execute(buf);
else return FALSE;
}
bool wxXLPHelpController::KeywordSearch(const wxString& k)
{
if (!helpRunning)
{
if (!Run())
return FALSE;
}
char buf[500];
sprintf(buf, "k %s", (const char*) k);
if (helpConnection)
return helpConnection->Execute(buf);
else return FALSE;
}
bool wxXLPHelpController::Quit(void)
{
if (helpConnection)
return helpConnection->Disconnect(); // Calls OnQuit via OnDisconnect
else return TRUE;
}
void wxXLPHelpController::OnQuit(void)
{
}
bool wxXLPHelpController::Run(void)
{
#ifdef __X__
if (!helpFile || !helpHost || helpRunning)
return FALSE;
#endif
#ifdef __WINDOWS__
if (!helpFile || helpRunning)
return FALSE;
#endif
time_t current_time;
#ifdef __X__
// Invent a server name that's likely to be unique but different from
// last time
(void)time(&current_time);
if (helpServer == -1)
helpServer = (int)(4000 + (current_time % 4000));
#else
// Only one instance of wxHelp at a time
helpServer = 4000;
#endif
char server[32];
sprintf(server, "%d", helpServer);
#ifdef __WINDOWS__
// Only one instance of wxHelp under Windows.
// See if there's already an instance of wxHelp
if ((helpConnection = (wxXLPHelpConnection *)helpClient.MakeConnection(helpHost, server, "WXHELP")))
{
helpRunning = TRUE;
return TRUE;
}
#endif
// Start help process in server modus
// char *argv[] = {"wxhelp", "-server", server, NULL}; // HP compiler complains
char *argv[4];
argv[0] = "wxhelp";
argv[1] = "-server";
argv[2] = server;
argv[3] = NULL;
if (wxExecute((char **)argv) == FALSE)
return FALSE; // Maybe we should print a message?
time_t start_time;
(void)time(&start_time);
// Give it some time to respond
do {
wxSleep(1);
helpConnection = (wxXLPHelpConnection *)helpClient.MakeConnection(helpHost, server, "WXHELP");
(void)time(&current_time);
} while (!helpConnection && ((current_time - start_time) < WX_HELP_TIMEOUT));
if (helpConnection == NULL) {
char buf[100];
sprintf(buf, (const char *) _("Connection to wxHelp timed out in %d seconds"), WX_HELP_TIMEOUT);
(void)wxMessageBox(buf, _("Error"));
return FALSE;
}
helpRunning = TRUE;
return TRUE;
}
wxXLPHelpConnection::wxXLPHelpConnection(wxXLPHelpController *instance)
{
helpInstance = instance;
}
bool wxXLPHelpConnection::OnDisconnect(void)
{
helpInstance->OnQuit();
helpInstance->helpRunning = FALSE;
helpInstance->helpConnection = NULL;
helpInstance->helpServer = -1;
delete this;
return TRUE;
}
#endif // USE_HELP

112
src/generic/imaglist.cpp Normal file
View File

@@ -0,0 +1,112 @@
/////////////////////////////////////////////////////////////////////////////
// Name: imaglist.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "imaglist.h"
#endif
#include "wx/imaglist.h"
//-----------------------------------------------------------------------------
// wxImageList
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
wxImageList::wxImageList(void)
{
Create();
};
wxImageList::~wxImageList(void)
{
};
int wxImageList::GetImageCount(void) const
{
return m_images.Number();
};
bool wxImageList::Create(void)
{
m_images.DeleteContents( TRUE );
return TRUE;
};
int wxImageList::Add( const wxBitmap &bitmap )
{
m_images.Append( new wxBitmap(bitmap) );
return m_images.Number();
};
bool wxImageList::Replace( const int index, const wxBitmap &bitmap )
{
wxNode *node = m_images.Nth( index );
if (!node) return FALSE;
if (index == m_images.Number()-1)
{
m_images.DeleteNode( node );
m_images.Append( new wxBitmap(bitmap) );
}
else
{
wxNode *next = node->Next();
m_images.DeleteNode( node );
m_images.Insert( next, new wxBitmap(bitmap) );
};
return TRUE;
};
bool wxImageList::Remove( const int index )
{
wxNode *node = m_images.Nth( index );
if (node) m_images.DeleteNode( node );
return (node != NULL);
};
bool wxImageList::RemoveAll(void)
{
m_images.Clear();
return TRUE;
};
bool wxImageList::GetSize( const int index, int &width, int &height ) const
{
wxNode *node = m_images.Nth( index );
if (node)
{
wxBitmap *bm = (wxBitmap*)node->Data();
width = bm->GetWidth();
height = bm->GetHeight();
return TRUE;
}
else
{
width = 0;
height = 0;
return FALSE;
};
};
bool wxImageList::Draw( const int index, wxDC &dc,
const int x, const int y,
const int WXUNUSED(flags), const bool WXUNUSED(solidBackground) )
{
wxNode *node = m_images.Nth( index );
if (!node) return FALSE;
wxBitmap *bm = (wxBitmap*)node->Data();
wxIcon *icon = (wxIcon*)bm;
dc.DrawIcon( *icon, x, y );
return TRUE;
};

2454
src/generic/listctrl.cpp Normal file

File diff suppressed because it is too large Load Diff

201
src/generic/msgdlgg.cpp Normal file
View File

@@ -0,0 +1,201 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msgdlgg.cpp
// Purpose: wxGenericMessageDialog
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "msgdlgg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/listbox.h"
#include "wx/button.h"
#include "wx/stattext.h"
#include "wx/layout.h"
#include "wx/intl.h"
#endif
#include <stdio.h>
#include <string.h>
#include "wx/generic/msgdlgg.h"
///////////////////////////////////////////////////////////////////
// New dialog box implementations
// Split message, using constraints to position controls
void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer)
{
char *copyMessage = copystring(message);
size_t i = 0;
size_t len = strlen(copyMessage);
char *currentMessage = copyMessage;
// wxWindow *lastWindow = parent;
while (i < len) {
while ((i < len) && (copyMessage[i] != '\n')) i++;
if (i < len) copyMessage[i] = 0;
wxStaticText *mess = new wxStaticText(parent, -1, currentMessage);
/*
wxLayoutConstraints *c = new wxLayoutConstraints;
c->left.SameAs (parent, wxLeft, 10);
c->top.SameAs (lastWindow, wxBottom, 5);
c->right.AsIs ();
c->height.AsIs ();
mess->SetConstraints(c);
*/
sizer->AddSizerChild(mess);
messageList->Append(mess);
currentMessage = copyMessage + i + 1;
}
delete[] copyMessage;
}
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
END_EVENT_TABLE()
IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
#endif
wxGenericMessageDialog::wxGenericMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
long style, const wxPoint& pos):
wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
m_dialogStyle = style;
wxBeginBusyCursor();
wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
topSizer->SetBorder(10, 10);
wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
messageSizer->SetName("messageSizer");
// bool centre = ((style & wxCENTRE) == wxCENTRE);
wxList messageList;
wxSplitMessage2(message, &messageList, this, messageSizer);
// Insert a spacer
wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 20);
wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
buttonSizer->SetName("buttonSizer");
// Specify constraints for the button sizer
wxLayoutConstraints *c = new wxLayoutConstraints;
c->width.AsIs ();
c->height.AsIs ();
c->top.Below (spacingSizer);
c->centreX.SameAs (spacingSizer, wxCentreX);
buttonSizer->SetConstraints(c);
wxButton *ok = NULL;
wxButton *cancel = NULL;
wxButton *yes = NULL;
wxButton *no = NULL;
if (style & wxYES_NO) {
yes = new wxButton(this, wxID_YES, _("Yes"));
no = new wxButton(this, wxID_NO, _("No"));
buttonSizer->AddSizerChild(yes);
buttonSizer->AddSizerChild(no);
}
if (style & wxOK) {
ok = new wxButton(this, wxID_OK, _("OK"));
buttonSizer->AddSizerChild(ok);
}
if (style & wxCANCEL) {
cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
buttonSizer->AddSizerChild(cancel);
}
if (ok)
{
ok->SetDefault();
ok->SetFocus();
}
else if (yes)
{
yes->SetDefault();
yes->SetFocus();
}
Layout();
Centre(wxBOTH);
wxEndBusyCursor();
}
void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
{
EndModal(wxID_YES);
}
void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
{
EndModal(wxID_NO);
}
void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
{
// Allow cancellation via ESC/Close button except if
// only YES and NO are specified.
if ( (m_dialogStyle & wxYES_NO) != wxYES_NO || (m_dialogStyle & wxCANCEL) )
EndModal(wxID_CANCEL);
}
int wxMessageBox(const wxString& message, const wxString& caption, const long style,
wxWindow *parent, const int WXUNUSED(x), const int WXUNUSED(y) )
{
wxMessageDialog dialog(parent, message, caption, style);
int ans = dialog.ShowModal();
switch ( ans )
{
case wxID_OK:
return wxOK;
break;
case wxID_YES:
return wxYES;
break;
case wxID_NO:
return wxNO;
break;
default:
case wxID_CANCEL:
return wxCANCEL;
break;
}
return ans;
}

82
src/generic/panelg.cpp Normal file
View File

@@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////
// Name: panelg.cpp
// Purpose: wxPanel
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "panelg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/settings.h"
#endif
#include "wx/generic/panelg.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
BEGIN_EVENT_TABLE(wxPanel, wxWindow)
EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged)
END_EVENT_TABLE()
#endif
wxPanel::wxPanel(void)
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
}
bool wxPanel::Create(wxWindow *parent, const wxWindowID id,
const wxPoint& pos,
const wxSize& size,
const long style,
const wxString& name)
{
bool ret = wxWindow::Create(parent, id, pos, size, style, name);
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
return ret;
}
void wxPanel::OnPaint(wxPaintEvent& WXUNUSED(event))
{
// No: if you call the default procedure, it makes
// the following painting code not work.
// wxWindow::OnPaint(event);
}
void wxPanel::InitDialog(void)
{
wxInitDialogEvent event(GetId());
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
// Responds to colour changes, and passes event on to children.
void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetDefaultBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
Refresh();
// Propagate the event to the non-top-level children
wxWindow::OnSysColourChanged(event);
}

264
src/generic/printps.cpp Normal file
View File

@@ -0,0 +1,264 @@
/////////////////////////////////////////////////////////////////////////////
// Name: printps.cpp
// Purpose: Postscript print/preview framework
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "printps.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/defs.h"
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/dc.h"
#include "wx/app.h"
#include "wx/msgdlg.h"
#endif
#include "wx/generic/printps.h"
#include "wx/dcprint.h"
#include "wx/printdlg.h"
#include "wx/generic/prntdlgg.h"
#include <stdlib.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter, wxPrinterBase)
IMPLEMENT_CLASS(wxPostScriptPrintPreview, wxPrintPreviewBase)
#endif
/*
* Printer
*/
wxPostScriptPrinter::wxPostScriptPrinter(wxPrintData *data):
wxPrinterBase(data)
{
}
wxPostScriptPrinter::~wxPostScriptPrinter(void)
{
}
bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
{
abortIt = FALSE;
abortWindow = NULL;
if (!printout)
return FALSE;
printout->SetIsPreview(FALSE);
printout->OnPreparePrinting();
// Get some parameters from the printout, if defined
int fromPage, toPage;
int minPage, maxPage;
printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
if (maxPage == 0)
return FALSE;
printData.SetMinPage(minPage);
printData.SetMaxPage(maxPage);
if (fromPage != 0)
printData.SetFromPage(fromPage);
if (toPage != 0)
printData.SetToPage(toPage);
if (minPage != 0)
{
printData.EnablePageNumbers(TRUE);
if (printData.GetFromPage() < printData.GetMinPage())
printData.SetFromPage(printData.GetMinPage());
else if (printData.GetFromPage() > printData.GetMaxPage())
printData.SetFromPage(printData.GetMaxPage());
if (printData.GetToPage() > printData.GetMaxPage())
printData.SetToPage(printData.GetMaxPage());
else if (printData.GetToPage() < printData.GetMinPage())
printData.SetToPage(printData.GetMinPage());
}
else
printData.EnablePageNumbers(FALSE);
// Create a suitable device context
wxDC *dc = NULL;
if (prompt)
{
wxGenericPrintDialog dialog(parent, & printData);
if (dialog.ShowModal() == wxID_OK)
{
dc = dialog.GetPrintDC();
printData = dialog.GetPrintData();
}
}
else
{
dc = new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, NULL);
}
// May have pressed cancel.
if (!dc || !dc->Ok())
{
if (dc) delete dc;
return FALSE;
}
int logPPIScreenX = 0;
int logPPIScreenY = 0;
int logPPIPrinterX = 0;
int logPPIPrinterY = 0;
// Correct values for X/PostScript?
logPPIScreenX = 100;
logPPIScreenY = 100;
logPPIPrinterX = 100;
logPPIPrinterY = 100;
printout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
// Set printout parameters
printout->SetDC(dc);
int w, h;
long ww, hh;
dc->GetSize(&w, &h);
printout->SetPageSizePixels((int)w, (int)h);
dc->GetSizeMM(&ww, &hh);
printout->SetPageSizeMM((int)ww, (int)hh);
// Create an abort window
wxBeginBusyCursor();
printout->OnBeginPrinting();
bool keepGoing = TRUE;
int copyCount;
for (copyCount = 1; copyCount <= printData.GetNoCopies(); copyCount ++)
{
if (!printout->OnBeginDocument(printData.GetFromPage(), printData.GetToPage()))
{
wxEndBusyCursor();
wxMessageBox("Could not start printing.", "Print Error", wxOK, parent);
break;
}
if (abortIt)
break;
int pn;
for (pn = printData.GetFromPage(); keepGoing && (pn <= printData.GetToPage()) && printout->HasPage(pn);
pn++)
{
if (abortIt)
{
keepGoing = FALSE;
break;
}
else
{
dc->StartPage();
printout->OnPrintPage(pn);
dc->EndPage();
}
}
printout->OnEndDocument();
}
printout->OnEndPrinting();
wxEndBusyCursor();
delete dc;
return TRUE;
}
bool wxPostScriptPrinter::PrintDialog(wxWindow *parent)
{
wxGenericPrintDialog dialog(parent, & printData);
return (dialog.ShowModal() == wxID_OK);
}
bool wxPostScriptPrinter::Setup(wxWindow *parent)
{
wxGenericPrintDialog dialog(parent, & printData);
dialog.GetPrintData().SetSetupDialog(TRUE);
return (dialog.ShowModal() == wxID_OK);
}
/*
* Print preview
*/
wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
wxPrintPreviewBase(printout, printoutForPrinting, data)
{
// Have to call it here since base constructor can't call it
DetermineScaling();
}
wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void)
{
}
bool wxPostScriptPrintPreview::Print(bool interactive)
{
if (!printPrintout)
return FALSE;
wxPostScriptPrinter printer(&printData);
return printer.Print(previewFrame, printPrintout, interactive);
}
void wxPostScriptPrintPreview::DetermineScaling(void)
{
char *paperType = wxThePrintSetupData->GetPaperName();
if (!paperType)
paperType = "A4 210 x 297 mm";
wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
if (!paper)
paper = wxThePrintPaperDatabase->FindPaperType("A4 210 x 297 mm");
if (paper)
{
previewPrintout->SetPPIScreen(100, 100);
previewPrintout->SetPPIPrinter(100, 100);
// If in landscape mode, we need to swap the width and height.
if ( printData.GetOrientation() == wxLANDSCAPE )
{
pageWidth = paper->heightPixels;
pageHeight = paper->widthPixels;
previewPrintout->SetPageSizeMM(paper->heightMM, paper->widthMM);
previewPrintout->SetPageSizePixels(paper->heightPixels, paper->widthPixels);
}
else
{
pageWidth = paper->widthPixels;
pageHeight = paper->heightPixels;
previewPrintout->SetPageSizeMM(paper->widthMM, paper->heightMM);
previewPrintout->SetPageSizePixels(paper->widthPixels, paper->heightPixels);
}
// At 100%, the page should look about page-size on the screen.
previewScale = (float)0.8;
// previewScale = (float)((float)screenWidth/(float)printerWidth);
// previewScale = previewScale * (float)((float)screenXRes/(float)printerYRes);
}
}

610
src/generic/prntdlgg.cpp Normal file
View File

@@ -0,0 +1,610 @@
/////////////////////////////////////////////////////////////////////////////
// Name: prntdlgg.cpp
// Purpose: Generic print dialogs
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "prntdlgg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/defs.h"
#define WINDOWS_PRINTING (wxTheApp->GetPrintMode() == wxPRINT_WINDOWS)
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/dc.h"
#include "wx/app.h"
#include "wx/frame.h"
#include "wx/stattext.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/textctrl.h"
#include "wx/radiobox.h"
#include "wx/filedlg.h"
#include "wx/choice.h"
#endif
#include "wx/generic/prntdlgg.h"
#include "wx/printdlg.h"
#include <stdlib.h>
#include <string.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxGenericPrintDialog, wxDialog)
IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog)
BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxDialog)
EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK)
EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup)
EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog)
EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
END_EVENT_TABLE()
#endif
extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
/*
* Generic print dialog for non-Windows printing use.
*/
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintData* data):
wxDialog(parent, -1, "Print", wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
if ( data )
printData = *data;
int buttonWidth = 65;
int buttonHeight = 25;
int spacing = 5;
int yPos = 5;
int xPos = 5;
wxButton *okButton = new wxButton(this, wxID_OK, "OK", wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight));
(void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight));
setupButton = new wxButton(this, wxPRINTID_SETUP, "Setup...", wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight));
okButton->SetDefault();
okButton->SetFocus();
yPos += 35;
wxString choices[2];
choices[0] = "All";
choices[1] = "Pages";
rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, "Print Range",
wxPoint(5, yPos), wxSize(-1, -1), 2, choices, 2);
rangeRadioBox->SetSelection(1);
yPos += 60;
xPos = 5;
int staticWidth = 45;
int textWidth = 40;
spacing = 10;
(void) new wxStaticText(this, wxPRINTID_STATIC, "From:", wxPoint(xPos, yPos));
xPos += staticWidth;
fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
xPos += spacing + textWidth;
(void) new wxStaticText(this, wxPRINTID_STATIC, "To:", wxPoint(xPos, yPos));
xPos += staticWidth;
toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
xPos += spacing + textWidth;
(void) new wxStaticText(this, wxPRINTID_STATIC, "Copies:", wxPoint(xPos, yPos));
xPos += spacing + staticWidth;
noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
yPos += 30;
xPos = 5;
printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, "Print to File", wxPoint(xPos, yPos));
Fit();
Centre(wxBOTH);
// Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
InitDialog();
}
int wxGenericPrintDialog::ShowModal(void)
{
if ( printData.GetSetupDialog() )
{
wxGenericPrintSetupDialog *genericPrintSetupDialog =
new wxGenericPrintSetupDialog(GetParent(), wxThePrintSetupData);
int ret = genericPrintSetupDialog->ShowModal();
if ( ret != wxID_CANCEL )
{
*wxThePrintSetupData = genericPrintSetupDialog->printData;
}
genericPrintSetupDialog->Close(TRUE);
return ret;
}
else
{
return wxDialog::ShowModal();
}
}
wxGenericPrintDialog::~wxGenericPrintDialog(void)
{
}
void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
TransferDataFromWindow();
// There are some interactions between the global setup data
// and the standard print dialog. The global printing 'mode'
// is determined by whether the user checks Print to file
// or not.
if (printData.GetPrintToFile())
{
wxThePrintSetupData->SetPrinterMode(PS_FILE);
char *f = wxFileSelector("PostScript file",
wxPathOnly(wxThePrintSetupData->GetPrinterFile()),
wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()),
"ps", "*.ps", 0, this);
if (f)
wxThePrintSetupData->SetPrinterFile(f);
else
return;
}
else
wxThePrintSetupData->SetPrinterMode(PS_PRINTER);
EndModal(wxID_OK);
}
void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
{
if (event.GetInt() == 0)
{
fromText->Enable(FALSE);
toText->Enable(FALSE);
}
else if (event.GetInt() == 1)
{
fromText->Enable(TRUE);
toText->Enable(TRUE);
}
}
void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
{
wxGenericPrintSetupDialog *genericPrintSetupDialog =
new wxGenericPrintSetupDialog(this, wxThePrintSetupData);
int ret = genericPrintSetupDialog->ShowModal();
if ( ret != wxID_CANCEL )
{
*wxThePrintSetupData = genericPrintSetupDialog->printData;
printData.SetOrientation(wxThePrintSetupData->GetPrinterOrientation());
}
genericPrintSetupDialog->Close(TRUE);
}
bool wxGenericPrintDialog::TransferDataToWindow(void)
{
char buf[10];
if (printData.GetEnablePageNumbers())
{
fromText->Enable(TRUE);
toText->Enable(TRUE);
sprintf(buf, "%d", printData.GetFromPage());
fromText->SetValue(buf);
sprintf(buf, "%d", printData.GetToPage());
toText->SetValue(buf);
if (printData.GetAllPages())
rangeRadioBox->SetSelection(0);
else
rangeRadioBox->SetSelection(1);
}
else
{
fromText->Enable(FALSE);
toText->Enable(FALSE);
rangeRadioBox->SetSelection(0);
rangeRadioBox->wxRadioBox::Enable(1, FALSE);
}
sprintf(buf, "%d", printData.GetNoCopies());
noCopiesText->SetValue(buf);
printToFileCheckBox->SetValue(printData.GetPrintToFile());
printToFileCheckBox->Enable(printData.GetEnablePrintToFile());
return TRUE;
}
bool wxGenericPrintDialog::TransferDataFromWindow(void)
{
if (printData.GetEnablePageNumbers())
{
printData.SetFromPage(atoi(fromText->GetValue()));
printData.SetToPage(atoi(toText->GetValue()));
}
if (rangeRadioBox->GetSelection() == 0)
printData.SetAllPages(TRUE);
else
printData.SetAllPages(FALSE);
printData.SetNoCopies(atoi(noCopiesText->GetValue()));
printData.SetPrintToFile(printToFileCheckBox->GetValue());
return TRUE;
}
wxDC *wxGenericPrintDialog::GetPrintDC(void)
{
return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, NULL);
}
/*
* Generic print setup dialog
*/
wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data):
wxDialog(parent, -1, "Print Setup", wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
if ( data )
printData = *data;
int buttonWidth = 65;
int buttonHeight = 25;
int spacing = 5;
int yPos = 5;
int xPos = 5;
wxButton *okButton = new wxButton(this, wxID_OK, "OK", wxPoint(xPos, yPos), wxSize(buttonWidth, buttonHeight));
xPos += buttonWidth + spacing;
(void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(xPos, yPos), wxSize(buttonWidth, buttonHeight));
okButton->SetDefault();
okButton->SetFocus();
yPos += 35;
xPos = 5;
paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos);
wxString choices[2];
choices[0] = "Portrait";
choices[1] = "Landscape";
orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, "Orientation",
wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2);
orientationRadioBox->SetSelection(0);
xPos += 200;
colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, "Print in colour", wxPoint(xPos, yPos));
xPos = 5;
yPos += 60;
int staticWidth = 100;
int textWidth = 120;
spacing = 10;
(void) new wxStaticText(this, wxPRINTID_STATIC, "Printer command:", wxPoint(xPos, yPos));
xPos += staticWidth;
printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
xPos += textWidth + spacing;
(void) new wxStaticText(this, wxPRINTID_STATIC, "Printer options:", wxPoint(xPos, yPos));
xPos += staticWidth;
printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
Fit();
Centre(wxBOTH);
InitDialog();
}
wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog(void)
{
}
bool wxGenericPrintSetupDialog::TransferDataToWindow(void)
{
if (printerCommandText && printData.GetPrinterCommand())
printerCommandText->SetValue(printData.GetPrinterCommand());
if (printerOptionsText && printData.GetPrinterOptions())
printerOptionsText->SetValue(printData.GetPrinterOptions());
if (colourCheckBox)
colourCheckBox->SetValue(printData.GetColour());
if (orientationRadioBox)
{
if (printData.GetPrinterOrientation() == PS_PORTRAIT)
orientationRadioBox->SetSelection(0);
else
orientationRadioBox->SetSelection(1);
}
return TRUE;
}
bool wxGenericPrintSetupDialog::TransferDataFromWindow(void)
{
if (printerCommandText)
printData.SetPrinterCommand(WXSTRINGCAST printerCommandText->GetValue());
if (printerOptionsText)
printData.SetPrinterOptions(WXSTRINGCAST printerOptionsText->GetValue());
if (colourCheckBox)
printData.SetColour(colourCheckBox->GetValue());
if (orientationRadioBox)
{
int sel = orientationRadioBox->GetSelection();
if (sel == 0)
printData.SetPrinterOrientation(PS_PORTRAIT);
else
printData.SetPrinterOrientation(PS_LANDSCAPE);
}
if (paperTypeChoice)
{
wxString val(paperTypeChoice->GetStringSelection());
if (!val.IsNull() && val != "")
printData.SetPaperName((char *)(const char *)val);
}
return TRUE;
}
wxChoice *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y)
{
if (!wxThePrintPaperDatabase)
{
wxThePrintPaperDatabase = new wxPrintPaperDatabase;
wxThePrintPaperDatabase->CreateDatabase();
}
int n = wxThePrintPaperDatabase->Number();
wxString *choices = new wxString [n];
int sel = 0;
int i;
for (i = 0; i < n; i++)
{
wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data();
choices[i] = paper->pageName;
if (printData.GetPaperName() && choices[i] == printData.GetPaperName())
sel = i;
}
(void) new wxStaticText(this, wxPRINTID_STATIC, "Paper size", wxPoint(*x, *y));
*y += 25;
wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(300, -1), n,
choices);
*y += 35;
delete[] choices;
choice->SetSelection(sel);
return choice;
}
/*
* Generic page setup dialog
*/
void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
{
if (wxTheApp->GetPrintMode() == wxPRINT_POSTSCRIPT)
{
wxGenericPrintSetupDialog *genericPrintSetupDialog =
new wxGenericPrintSetupDialog(this, wxThePrintSetupData);
int ret = genericPrintSetupDialog->ShowModal();
if (ret == wxID_OK)
*wxThePrintSetupData = genericPrintSetupDialog->GetPrintData();
genericPrintSetupDialog->Close(TRUE);
}
#ifdef __WINDOWS__
else
{
wxPrintData data;
data.SetSetupDialog(TRUE);
wxPrintDialog printDialog(this, & data);
printDialog.Show(TRUE);
}
#endif
}
wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data):
wxDialog(parent, -1, "Page Setup", wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE)
{
if ( data )
pageData = *data;
int buttonWidth = 75;
int buttonHeight = 25;
int spacing = 5;
int yPos = 5;
int xPos = 5;
wxButton *okButton = new wxButton(this, wxID_OK, "OK", wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight));
(void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight));
printerButton = new wxButton(this, wxPRINTID_SETUP, "Printer...", wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight));
if ( !pageData.GetEnablePrinter() )
printerButton->Enable(FALSE);
// if (printData.GetEnableHelp())
// wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, "Help", -1, -1, buttonWidth, buttonHeight);
okButton->SetDefault();
okButton->SetFocus();
xPos = 5;
yPos += 35;
paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos);
xPos = 5;
wxString choices[2];
choices[0] = "Portrait";
choices[1] = "Landscape";
orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, "Orientation",
wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2);
orientationRadioBox->SetSelection(0);
xPos = 5;
yPos += 60;
int staticWidth = 110;
int textWidth = 60;
spacing = 10;
(void) new wxStaticText(this, wxPRINTID_STATIC, "Left margin (mm):", wxPoint(xPos, yPos));
xPos += staticWidth;
marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
xPos += textWidth + spacing;
(void) new wxStaticText(this, wxPRINTID_STATIC, "Right margin (mm):", wxPoint(xPos, yPos));
xPos += staticWidth;
marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
xPos += textWidth + spacing;
yPos += 35;
xPos = 5;
(void) new wxStaticText(this, wxPRINTID_STATIC, "Top margin (mm):", wxPoint(xPos, yPos));
xPos += staticWidth;
marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
xPos += textWidth + spacing;
(void) new wxStaticText(this, wxPRINTID_STATIC, "Bottom margin (mm):", wxPoint(xPos, yPos));
xPos += staticWidth;
marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
Fit();
Centre(wxBOTH);
InitDialog();
}
wxGenericPageSetupDialog::~wxGenericPageSetupDialog(void)
{
}
bool wxGenericPageSetupDialog::TransferDataToWindow(void)
{
if (marginLeftText)
marginLeftText->SetValue(IntToString((int) pageData.GetMarginTopLeft().x));
if (marginTopText)
marginTopText->SetValue(IntToString((int) pageData.GetMarginTopLeft().y));
if (marginRightText)
marginRightText->SetValue(IntToString((int) pageData.GetMarginBottomRight().x));
if (marginBottomText)
marginBottomText->SetValue(IntToString((int) pageData.GetMarginBottomRight().y));
if (orientationRadioBox)
{
if (pageData.GetOrientation() == wxPORTRAIT)
orientationRadioBox->SetSelection(0);
else
orientationRadioBox->SetSelection(1);
}
return TRUE;
}
bool wxGenericPageSetupDialog::TransferDataFromWindow(void)
{
if (marginLeftText && marginTopText)
pageData.SetMarginTopLeft(wxPoint(atoi((const char *)marginLeftText->GetValue()),atoi((const char *)marginTopText->GetValue())));
if (marginRightText && marginBottomText)
pageData.SetMarginBottomRight(wxPoint(atoi((const char *)marginRightText->GetValue()),atoi((const char *)marginBottomText->GetValue())));
if (orientationRadioBox)
{
int sel = orientationRadioBox->GetSelection();
if (sel == 0)
{
wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT);
pageData.SetOrientation(wxPORTRAIT);
}
else
{
wxThePrintSetupData->SetPrinterOrientation(wxLANDSCAPE);
pageData.SetOrientation(wxLANDSCAPE);
}
}
if (paperTypeChoice)
{
wxString val(paperTypeChoice->GetStringSelection());
if (!val.IsNull() && val != "")
{
wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType((char*) (const char *)val);
if ( paper )
{
pageData.SetPaperSize(wxPoint(paper->widthMM, paper->heightMM));
}
}
}
return TRUE;
}
wxChoice *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
{
if (!wxThePrintPaperDatabase)
{
wxThePrintPaperDatabase = new wxPrintPaperDatabase;
wxThePrintPaperDatabase->CreateDatabase();
}
int n = wxThePrintPaperDatabase->Number();
wxString *choices = new wxString [n];
int sel = 0;
int i;
for (i = 0; i < n; i++)
{
wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data();
choices[i] = paper->pageName;
if (pageData.GetPaperSize().x == paper->widthMM && pageData.GetPaperSize().y == paper->heightMM)
sel = i;
}
(void) new wxStaticText(this, wxPRINTID_STATIC, "Paper size", wxPoint(*x, *y));
*y += 25;
wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(300, -1), n,
choices);
*y += 35;
delete[] choices;
choice->SetSelection(sel);
return choice;
}

442
src/generic/scrolwin.cpp Normal file
View File

@@ -0,0 +1,442 @@
/////////////////////////////////////////////////////////////////////////////
// Name: scrolwin.cpp
// Purpose: wxScrolledWindow implementation
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#pragma implementation "scrolwin.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/utils.h"
#include "wx/dcclient.h"
#ifdef __WINDOWS__
#include "windows.h"
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/generic/scrolwin.h"
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxScrolledWindow, wxWindow)
EVT_SCROLL(wxScrolledWindow::OnScroll)
EVT_SIZE(wxScrolledWindow::OnSize)
EVT_PAINT(wxScrolledWindow::OnPaint)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxWindow)
#endif
wxScrolledWindow::wxScrolledWindow(void)
{
m_xScrollPixelsPerLine = 0;
m_yScrollPixelsPerLine = 0;
m_xScrollingEnabled = TRUE;
m_yScrollingEnabled = TRUE;
m_xScrollPosition = 0;
m_yScrollPosition = 0;
m_xScrollLines = 0;
m_yScrollLines = 0;
m_xScrollLinesPerPage = 0;
m_yScrollLinesPerPage = 0;
}
bool wxScrolledWindow::Create(wxWindow *parent, const wxWindowID id,
const wxPoint& pos,
const wxSize& size,
const long style,
const wxString& name)
{
m_xScrollPixelsPerLine = 0;
m_yScrollPixelsPerLine = 0;
m_xScrollingEnabled = TRUE;
m_yScrollingEnabled = TRUE;
m_xScrollPosition = 0;
m_yScrollPosition = 0;
m_xScrollLines = 0;
m_yScrollLines = 0;
m_xScrollLinesPerPage = 0;
m_yScrollLinesPerPage = 0;
return wxWindow::Create(parent, id, pos, size, style, name);
}
/*
* pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
* noUnitsX/noUnitsY: : no. units per scrollbar
*/
void wxScrolledWindow::SetScrollbars (const int pixelsPerUnitX, const int pixelsPerUnitY,
const int noUnitsX, const int noUnitsY,
const int xPos, const int yPos, const bool noRefresh )
{
bool do_refresh =
(
(noUnitsX != 0 && m_xScrollLines == 0) ||
(noUnitsX < m_xScrollPosition) ||
(noUnitsY != 0 && m_yScrollLines == 0) ||
(noUnitsY < m_yScrollPosition) ||
(xPos != m_xScrollPosition) ||
(yPos != m_yScrollPosition) ||
(pixelsPerUnitX != m_xScrollPixelsPerLine) ||
(pixelsPerUnitY != m_yScrollPixelsPerLine)
);
m_xScrollPixelsPerLine = pixelsPerUnitX;
m_yScrollPixelsPerLine = pixelsPerUnitY;
m_xScrollLines = noUnitsX;
m_yScrollLines = noUnitsY;
AdjustScrollbars();
if (do_refresh && !noRefresh) Refresh();
#ifdef __WINDOWS__
UpdateWindow ((HWND) GetHWND());
#endif
}
void wxScrolledWindow::OnScroll(wxScrollEvent& event)
{
int orient = event.GetOrientation();
int nScrollInc = CalcScrollInc(event);
if (nScrollInc == 0)
return;
// TODO: should we store the scroll position here as well as in wxWindow?
if (orient == wxHORIZONTAL)
{
int newPos = m_xScrollPosition + nScrollInc;
SetScrollPos(wxHORIZONTAL, newPos, TRUE );
}
else
{
int newPos = m_yScrollPosition + nScrollInc;
SetScrollPos(wxVERTICAL, newPos, TRUE );
}
/*
// TODO We need to multiply the ScrollWindow amount by the scaling
// factor, but how do we know what this is in wxWin 2.0???
float scaleX = 1.0;
float scaleY = 1.0;
if ( this->IsKindOf(CLASSINFO(wxCanvas)) )
{
wxDC* dc = ((wxCanvas *)this)->GetDC();
dc->GetUserScale(&scaleX, &scaleY);
}
*/
if (orient == wxHORIZONTAL)
{
m_xScrollPosition += nScrollInc;
}
else
{
m_yScrollPosition += nScrollInc;
}
if (orient == wxHORIZONTAL)
{
if (m_xScrollingEnabled)
ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, NULL);
else
Refresh();
}
else
{
if (m_yScrollingEnabled)
ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, NULL);
else
Refresh();
}
}
int wxScrolledWindow::CalcScrollInc(wxScrollEvent& event)
{
int pos = event.GetPosition();
int orient = event.GetOrientation();
int nScrollInc = 0;
switch (event.GetEventType())
{
case wxEVENT_TYPE_SCROLL_TOP:
{
if (orient == wxHORIZONTAL)
nScrollInc = - m_xScrollPosition;
else
nScrollInc = - m_yScrollPosition;
break;
}
case wxEVENT_TYPE_SCROLL_BOTTOM:
{
if (orient == wxHORIZONTAL)
nScrollInc = m_xScrollLines - m_xScrollPosition;
else
nScrollInc = m_yScrollLines - m_yScrollPosition;
break;
}
case wxEVENT_TYPE_SCROLL_LINEUP:
{
nScrollInc = -1;
break;
}
case wxEVENT_TYPE_SCROLL_LINEDOWN:
{
nScrollInc = 1;
break;
}
case wxEVENT_TYPE_SCROLL_PAGEUP:
{
if (orient == wxHORIZONTAL)
nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
else
nScrollInc = -GetScrollPageSize(wxVERTICAL);
break;
}
case wxEVENT_TYPE_SCROLL_PAGEDOWN:
{
if (orient == wxHORIZONTAL)
nScrollInc = GetScrollPageSize(wxHORIZONTAL);
else
nScrollInc = GetScrollPageSize(wxVERTICAL);
break;
}
case wxEVENT_TYPE_SCROLL_THUMBTRACK:
{
if (orient == wxHORIZONTAL)
nScrollInc = pos - m_xScrollPosition;
else
nScrollInc = pos - m_yScrollPosition;
break;
}
default:
{
break;
}
}
if (orient == wxHORIZONTAL)
{
int w, h;
GetClientSize(&w, &h);
int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
int noPositions = (int) ( ((nMaxWidth - w)/(float)m_xScrollPixelsPerLine) + 0.5 );
if (noPositions < 0)
noPositions = 0;
if ( (m_xScrollPosition + nScrollInc) < 0 )
nScrollInc = -m_xScrollPosition; // As -ve as we can go
else if ( (m_xScrollPosition + nScrollInc) > noPositions )
nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
return nScrollInc;
}
else
{
int w, h;
GetClientSize(&w, &h);
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
int noPositions = (int) ( ((nMaxHeight - h)/(float)m_yScrollPixelsPerLine) + 0.5 );
if (noPositions < 0)
noPositions = 0;
if ( (m_yScrollPosition + nScrollInc) < 0 )
nScrollInc = -m_yScrollPosition; // As -ve as we can go
else if ( (m_yScrollPosition + nScrollInc) > noPositions )
nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
return nScrollInc;
}
}
// Adjust the scrollbars - new version.
void wxScrolledWindow::AdjustScrollbars(void)
{
int w, h;
GetClientSize(&w, &h);
// Recalculate scroll bar range and position
if (m_xScrollLines > 0)
{
int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
int newRange = (int) ( ((nMaxWidth)/(float)m_xScrollPixelsPerLine) + 0.5 );
if (newRange < 0)
newRange = 0;
m_xScrollPosition = wxMin(newRange, m_xScrollPosition);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1)
noPagePositions = 1;
SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange);
SetScrollPageSize(wxHORIZONTAL, noPagePositions);
}
// Robert Roebling
else
{
m_xScrollPosition = 0;
SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE);
}
if (m_yScrollLines > 0)
{
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
int newRange = (int) ( ((nMaxHeight)/(float)m_yScrollPixelsPerLine) + 0.5 );
if (newRange < 0)
newRange = 0;
m_yScrollPosition = wxMin(newRange, m_yScrollPosition);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1)
noPagePositions = 1;
SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange);
SetScrollPageSize(wxVERTICAL, noPagePositions);
}
else
{
m_yScrollPosition = 0;
SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); // Robert Roebling
}
}
// Default OnSize resets scrollbars, if any
void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
{
#if USE_CONSTRAINTS
if (GetAutoLayout())
Layout();
#endif
AdjustScrollbars();
}
// This calls OnDraw, having adjusted the origin according to the current
// scroll position
void wxScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
PrepareDC(dc);
OnDraw(dc);
}
// Override this function if you don't want to have wxScrolledWindow
// automatically change the origin according to the scroll position.
void wxScrolledWindow::PrepareDC(wxDC& dc)
{
dc.SetDeviceOrigin(- m_xScrollPosition * m_xScrollPixelsPerLine, - m_yScrollPosition * m_yScrollPixelsPerLine);
}
#if WXWIN_COMPATIBILITY
void wxScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const
{
*x_page = GetScrollPageSize(wxHORIZONTAL);
*y_page = GetScrollPageSize(wxVERTICAL);
}
#endif
void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
{
*x_unit = m_xScrollPixelsPerLine;
*y_unit = m_yScrollPixelsPerLine;
}
int wxScrolledWindow::GetScrollPageSize(int orient) const
{
if ( orient == wxHORIZONTAL )
return m_xScrollLinesPerPage;
else
return m_yScrollLinesPerPage;
}
void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize)
{
if ( orient == wxHORIZONTAL )
m_xScrollLinesPerPage = pageSize;
else
m_yScrollLinesPerPage = pageSize;
}
/*
* Scroll to given position (scroll position, not pixel position)
*/
void wxScrolledWindow::Scroll (const int x_pos, const int y_pos)
{
int old_x, old_y;
ViewStart (&old_x, &old_y);
if (((x_pos == -1) || (x_pos == old_x)) && ((y_pos == -1) || (y_pos == old_y)))
return;
if (x_pos > -1)
{
m_xScrollPosition = x_pos;
SetScrollPos (wxHORIZONTAL, x_pos, TRUE);
}
if (y_pos > -1)
{
m_yScrollPosition = y_pos;
SetScrollPos (wxVERTICAL, y_pos, TRUE);
}
Refresh();
#ifdef __WINDOWS__
::UpdateWindow ((HWND) GetHWND());
#endif
}
void wxScrolledWindow::EnableScrolling (const bool x_scroll, const bool y_scroll)
{
m_xScrollingEnabled = x_scroll;
m_yScrollingEnabled = y_scroll;
}
void wxScrolledWindow::GetVirtualSize (int *x, int *y) const
{
*x = m_xScrollPixelsPerLine * m_xScrollLines;
*y = m_yScrollPixelsPerLine * m_yScrollLines;
}
// Where the current view starts from
void wxScrolledWindow::ViewStart (int *x, int *y) const
{
*x = m_xScrollPosition;
*y = m_yScrollPosition;
}
void wxScrolledWindow::CalcScrolledPosition(const int x, const int y, int *xx, int *yy) const
{
*xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
*yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
}
void wxScrolledWindow::CalcUnscrolledPosition(const int x, const int y, float *xx, float *yy) const
{
*xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine);
*yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine);
}

729
src/generic/splitter.cpp Normal file
View File

@@ -0,0 +1,729 @@
/////////////////////////////////////////////////////////////////////////////
// Name: splitter.cpp
// Purpose: wxSplitterWindow implementation
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "splitter.h"
// #pragma interface
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <math.h>
#include <stdlib.h>
#include "wx/string.h"
#include "wx/splitter.h"
#include "wx/dcscreen.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow, wxWindow)
BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
EVT_PAINT(wxSplitterWindow::OnPaint)
EVT_SIZE(wxSplitterWindow::OnSize)
EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
END_EVENT_TABLE()
#endif
wxSplitterWindow::wxSplitterWindow(void)
{
m_splitMode = wxSPLIT_VERTICAL;
m_windowOne = NULL;
m_windowTwo = NULL;
m_dragMode = wxSPLIT_DRAG_NONE;
m_oldX = 0;
m_oldY = 0;
m_firstX = 0;
m_firstY = 0;
m_sashSize = 7;
m_borderSize = 2;
m_sashPosition = 0;
m_sashCursorWE = NULL;
m_sashCursorNS = NULL;
m_sashTrackerPen = NULL;
m_lightShadowPen = NULL;
m_mediumShadowPen = NULL;
m_darkShadowPen = NULL;
m_faceBrush = NULL;
m_facePen = NULL;
m_hilightPen = NULL;
m_minimumPaneSize = 0;
}
wxSplitterWindow::wxSplitterWindow(wxWindow *parent, const wxWindowID id, const wxPoint& pos,
const wxSize& size, const long style, const wxString& name)
:wxWindow(parent, id, pos, size, style, name)
{
m_splitMode = wxSPLIT_VERTICAL;
m_windowOne = NULL;
m_windowTwo = NULL;
m_dragMode = wxSPLIT_DRAG_NONE;
m_oldX = 0;
m_oldY = 0;
m_firstX = 0;
m_firstY = 0;
m_sashSize = 7;
m_borderSize = 2;
m_sashPosition = 0;
m_minimumPaneSize = 0;
m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
m_sashTrackerPen = new wxPen(*wxBLACK, 2, wxSOLID);
m_lightShadowPen = NULL;
m_mediumShadowPen = NULL;
m_darkShadowPen = NULL;
m_faceBrush = NULL;
m_facePen = NULL;
m_hilightPen = NULL;
if ( style & wxSP_3D )
{
m_borderSize = 2;
m_sashSize = 7;
}
else if ( style & wxSP_BORDER )
{
m_borderSize = 1;
m_sashSize = 3;
}
else
{
m_borderSize = 0;
m_sashSize = 3;
}
// Eventually, we'll respond to colour change messages
InitColours();
SetDoubleClick(TRUE);
// For debugging purposes, to see the background.
// SetBackground(wxBLUE_BRUSH);
}
wxSplitterWindow::~wxSplitterWindow(void)
{
delete m_sashCursorWE;
delete m_sashCursorNS;
delete m_sashTrackerPen;
delete m_lightShadowPen;
delete m_darkShadowPen;
delete m_mediumShadowPen;
delete m_hilightPen;
delete m_facePen;
delete m_faceBrush;
}
void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
if ( m_borderSize > 0 )
DrawBorders(dc);
DrawSash(dc);
}
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
{
long x, y;
event.Position(&x, &y);
if (event.LeftDown())
{
if ( SashHitTest(x, y) )
{
CaptureMouse();
// Required for X to specify that
// that we wish to draw on top of all windows
// - and we optimise by specifying the area
// for creating the overlap window.
wxScreenDC::StartDrawingOnTop(this);
// We don't say we're dragging yet; we leave that
// decision for the Dragging() branch, to ensure
// the user has dragged a little bit.
m_dragMode = wxSPLIT_DRAG_LEFT_DOWN;
m_firstX = x;
m_firstY = y;
}
}
else if ( event.LeftUp() && m_dragMode == wxSPLIT_DRAG_LEFT_DOWN )
{
// Wasn't a proper drag
ReleaseMouse();
wxScreenDC::EndDrawingOnTop();
m_dragMode = wxSPLIT_DRAG_NONE;
SetCursor(*wxSTANDARD_CURSOR);
wxSetCursor(*wxSTANDARD_CURSOR);
}
else if (event.LeftUp() && m_dragMode == wxSPLIT_DRAG_DRAGGING)
{
// We can stop dragging now and see what we've got.
m_dragMode = wxSPLIT_DRAG_NONE;
ReleaseMouse();
// Erase old tracker
DrawSashTracker(m_oldX, m_oldY);
// End drawing on top (frees the window used for drawing
// over the screen)
wxScreenDC::EndDrawingOnTop();
int w, h;
GetClientSize(&w, &h);
if ( m_splitMode == wxSPLIT_VERTICAL )
{
// First check if we should veto this resize because
// the pane size is too small
if ( wxMax(x, 0) < m_minimumPaneSize || wxMax((w - x), 0) < m_minimumPaneSize)
return;
if ( x <= 4 )
{
// We remove the first window from the view
wxWindow *removedWindow = m_windowOne;
m_windowOne = m_windowTwo;
m_windowTwo = NULL;
OnUnsplit(removedWindow);
m_sashPosition = 0;
}
else if ( x >= (w - 4) )
{
// We remove the second window from the view
wxWindow *removedWindow = m_windowTwo;
m_windowTwo = NULL;
OnUnsplit(removedWindow);
m_sashPosition = 0;
}
else
{
m_sashPosition = x;
}
}
else
{
// First check if we should veto this resize because
// the pane size is too small
if ( wxMax(y, 0) < m_minimumPaneSize || wxMax((h - y), 0) < m_minimumPaneSize)
return;
if ( y <= 4 )
{
// We remove the first window from the view
wxWindow *removedWindow = m_windowOne;
m_windowOne = m_windowTwo;
m_windowTwo = NULL;
OnUnsplit(removedWindow);
m_sashPosition = 0;
}
else if ( y >= (h - 4) )
{
// We remove the second window from the view
wxWindow *removedWindow = m_windowTwo;
m_windowTwo = NULL;
OnUnsplit(removedWindow);
m_sashPosition = 0;
}
else
{
m_sashPosition = y;
}
}
SizeWindows();
}
else if (event.Moving() && !event.Dragging())
{
// Just change the cursor if required
if ( SashHitTest(x, y) )
{
if ( m_splitMode == wxSPLIT_VERTICAL )
{
SetCursor(*m_sashCursorWE);
// Windows needs the following
wxSetCursor(*m_sashCursorWE);
}
else
{
SetCursor(*m_sashCursorNS);
wxSetCursor(*m_sashCursorNS);
}
}
else
{
SetCursor(*wxSTANDARD_CURSOR);
wxSetCursor(*wxSTANDARD_CURSOR);
}
}
else if ( (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING)) ||
(event.Dragging() && SashHitTest(x, y, 4)) )
{
if ( m_splitMode == wxSPLIT_VERTICAL )
{
SetCursor(*m_sashCursorWE);
wxSetCursor(*m_sashCursorWE);
}
else
{
SetCursor(*m_sashCursorNS);
wxSetCursor(*m_sashCursorNS);
}
// Detect that this is really a drag: we've moved more than 1 pixel either way
if ((m_dragMode == wxSPLIT_DRAG_LEFT_DOWN) &&
// (abs((int)x - m_firstX) > 1 || abs((int)y - m_firstY) > 1) )
(abs((int)x - m_firstX) > 0 || abs((int)y - m_firstY) > 1) )
{
m_dragMode = wxSPLIT_DRAG_DRAGGING;
DrawSashTracker(x, y);
}
else
{
if ( m_dragMode == wxSPLIT_DRAG_DRAGGING )
{
// Erase old tracker
DrawSashTracker(m_oldX, m_oldY);
// Draw new one
DrawSashTracker(x, y);
}
}
m_oldX = x;
m_oldY = y;
}
else if ( event.LeftDClick() )
{
OnDoubleClickSash(x, y);
}
else
{
SetCursor(*wxSTANDARD_CURSOR);
wxSetCursor(*wxSTANDARD_CURSOR);
}
}
void wxSplitterWindow::OnSize(wxSizeEvent& WXUNUSED(event))
{
int cw, ch;
GetClientSize( &cw, &ch );
if ( m_windowTwo )
{
if ( m_splitMode == wxSPLIT_VERTICAL )
{
if ( m_sashPosition >= (cw - 5) )
m_sashPosition = wxMax(10, cw - 40);
}
if ( m_splitMode == wxSPLIT_HORIZONTAL )
{
if ( m_sashPosition >= (ch - 5) )
m_sashPosition = wxMax(10, ch - 40);
}
}
SizeWindows();
}
bool wxSplitterWindow::SashHitTest(const int x, const int y, const int tolerance)
{
if ( m_windowTwo == NULL || m_sashPosition == 0)
return FALSE; // No sash
if ( m_splitMode == wxSPLIT_VERTICAL )
{
if ( (x >= m_sashPosition - tolerance) && (x <= m_sashPosition + m_sashSize + tolerance) )
return TRUE;
else
return FALSE;
}
else
{
if ( (y >= (m_sashPosition- tolerance)) && (y <= (m_sashPosition + m_sashSize + tolerance)) )
return TRUE;
else
return FALSE;
}
return FALSE;
}
// Draw 3D effect borders
void wxSplitterWindow::DrawBorders(wxDC& dc)
{
int w, h;
GetClientSize(&w, &h);
if ( GetWindowStyleFlag() & wxSP_3D )
{
dc.SetPen(*m_mediumShadowPen);
dc.DrawLine(0, 0, w-1, 0);
dc.DrawLine(0, 0, 0, h - 1);
dc.SetPen(*m_darkShadowPen);
dc.DrawLine(1, 1, w-2, 1);
dc.DrawLine(1, 1, 1, h-2);
dc.SetPen(*m_hilightPen);
dc.DrawLine(0, h-1, w-1, h-1);
dc.DrawLine(w-1, 0, w-1, h); // Surely the maximum y pos. should be h - 1.
/// Anyway, h is required for MSW.
dc.SetPen(*m_lightShadowPen);
dc.DrawLine(w-2, 1, w-2, h-2); // Right hand side
dc.DrawLine(1, h-2, w-1, h-2); // Bottom
}
else if ( GetWindowStyleFlag() & wxSP_BORDER )
{
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(*wxBLACK_PEN);
dc.DrawRectangle(0, 0, w-1, h-1);
}
dc.SetPen(wxNullPen);
dc.SetBrush(wxNullBrush);
}
// Draw the sash
void wxSplitterWindow::DrawSash(wxDC& dc)
{
if ( m_sashPosition == 0 || !m_windowTwo)
return;
int w, h;
GetClientSize(&w, &h);
if ( GetWindowStyleFlag() & wxSP_3D )
{
if ( m_splitMode == wxSPLIT_VERTICAL )
{
dc.SetPen(*m_facePen);
dc.SetBrush(*m_faceBrush);
dc.DrawRectangle(m_sashPosition + 2, 0, m_sashSize - 4, h);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(*m_lightShadowPen);
dc.DrawLine(m_sashPosition, 1, m_sashPosition, h-2);
dc.SetPen(*m_hilightPen);
dc.DrawLine(m_sashPosition+1, 0, m_sashPosition+1, h);
dc.SetPen(*m_mediumShadowPen);
dc.DrawLine(m_sashPosition+m_sashSize-2, 1, m_sashPosition+m_sashSize-2, h-1);
dc.SetPen(*m_darkShadowPen);
dc.DrawLine(m_sashPosition+m_sashSize-1, 2, m_sashPosition+m_sashSize-1, h-2);
}
else
{
dc.SetPen(*m_facePen);
dc.SetBrush(*m_faceBrush);
dc.DrawRectangle(0, m_sashPosition + 2, w, m_sashSize - 4);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(*m_lightShadowPen);
dc.DrawLine(1, m_sashPosition, w-2, m_sashPosition);
dc.SetPen(*m_hilightPen);
dc.DrawLine(0, m_sashPosition+1, w, m_sashPosition+1);
dc.SetPen(*m_mediumShadowPen);
dc.DrawLine(1, m_sashPosition+m_sashSize-2, w-1, m_sashPosition+m_sashSize-2);
dc.SetPen(*m_darkShadowPen);
dc.DrawLine(2, m_sashPosition+m_sashSize-1, w-2, m_sashPosition+m_sashSize-1);
}
}
else
{
if ( m_splitMode == wxSPLIT_VERTICAL )
{
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxBLACK_BRUSH);
int h1 = h-1;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER )
h1 += 1; // Not sure why this is necessary...
dc.DrawRectangle(m_sashPosition, 0, m_sashSize, h1);
}
else
{
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxBLACK_BRUSH);
int w1 = w-1;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER )
w1 ++;
dc.DrawRectangle(0, m_sashPosition, w1, m_sashSize);
}
}
dc.SetPen(wxNullPen);
dc.SetBrush(wxNullBrush);
}
// Draw the sash tracker (for whilst moving the sash)
void wxSplitterWindow::DrawSashTracker(const int x, const int y)
{
int w, h;
GetClientSize(&w, &h);
wxScreenDC screenDC;
int x1, y1;
int x2, y2;
if ( m_splitMode == wxSPLIT_VERTICAL )
{
x1 = x; y1 = 2;
x2 = x; y2 = h-2;
if ( x1 > w )
{
x1 = w; x2 = w;
}
else if ( x1 < 0 )
{
x1 = 0; x2 = 0;
}
}
else
{
x1 = 2; y1 = y;
x2 = w-2; y2 = y;
if ( y1 > h )
{
y1 = h;
y2 = h;
}
else if ( y1 < 0 )
{
y1 = 0;
y2 = 0;
}
}
ClientToScreen(&x1, &y1);
ClientToScreen(&x2, &y2);
screenDC.SetLogicalFunction(wxXOR);
screenDC.SetPen(*m_sashTrackerPen);
screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
screenDC.DrawLine(x1, y1, x2, y2);
screenDC.SetLogicalFunction(wxCOPY);
screenDC.SetPen(wxNullPen);
screenDC.SetBrush(wxNullBrush);
}
// Position and size subwindows.
// Note that the border size applies to each subwindow, not
// including the edges next to the sash.
void wxSplitterWindow::SizeWindows(void)
{
int w, h;
GetClientSize(&w, &h);
if ( m_windowOne && !m_windowTwo )
{
m_windowOne->SetSize(m_borderSize, m_borderSize, w - 2*m_borderSize, h - 2*m_borderSize);
}
else if ( m_windowOne && m_windowTwo )
{
if (m_splitMode == wxSPLIT_VERTICAL)
{
int x1 = m_borderSize;
int y1 = m_borderSize;
int w1 = m_sashPosition - m_borderSize;
int h1 = h - 2*m_borderSize;
int x2 = m_sashPosition + m_sashSize;
int y2 = m_borderSize;
int w2 = w - 2*m_borderSize - m_sashSize - w1;
int h2 = h - 2*m_borderSize;
m_windowOne->SetSize(x1, y1,
w1, h1);
m_windowTwo->SetSize(x2, y2,
w2, h2);
}
else
{
m_windowOne->SetSize(m_borderSize, m_borderSize,
w - 2*m_borderSize, m_sashPosition - m_borderSize);
m_windowTwo->SetSize(m_borderSize, m_sashPosition + m_sashSize,
w - 2*m_borderSize, h - 2*m_borderSize - m_sashSize - (m_sashPosition - m_borderSize));
}
}
wxClientDC dc(this);
DrawBorders(dc);
DrawSash(dc);
}
// Set pane for unsplit window
void wxSplitterWindow::Initialize(wxWindow *window)
{
m_windowOne = window;
m_windowTwo = NULL;
m_sashPosition = 0;
}
// Associates the given window with window 2, drawing the appropriate sash
// and changing the split mode.
// Does nothing and returns FALSE if the window is already split.
bool wxSplitterWindow::SplitVertically(wxWindow *window1, wxWindow *window2, const int sashPosition)
{
if ( IsSplit() )
return FALSE;
m_splitMode = wxSPLIT_VERTICAL;
m_windowOne = window1;
m_windowTwo = window2;
if ( sashPosition == -1 )
m_sashPosition = 100;
else
m_sashPosition = sashPosition;
SizeWindows();
return TRUE;
}
bool wxSplitterWindow::SplitHorizontally(wxWindow *window1, wxWindow *window2, const int sashPosition)
{
if ( IsSplit() )
return FALSE;
m_splitMode = wxSPLIT_HORIZONTAL;
m_windowOne = window1;
m_windowTwo = window2;
if ( sashPosition == -1 )
m_sashPosition = 100;
else
m_sashPosition = sashPosition;
SizeWindows();
return TRUE;
}
// Remove the specified (or second) window from the view
// Doesn't actually delete the window.
bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
{
if ( ! IsSplit() )
return FALSE;
if ( toRemove == NULL || toRemove == m_windowTwo)
{
wxWindow *win = m_windowTwo ;
m_windowTwo = NULL;
m_sashPosition = 0;
OnUnsplit(win);
SizeWindows();
}
else if ( toRemove == m_windowOne )
{
wxWindow *win = m_windowOne ;
m_windowOne = m_windowTwo;
m_windowTwo = NULL;
m_sashPosition = 0;
OnUnsplit(win);
SizeWindows();
}
else
return FALSE;
return TRUE;
}
void wxSplitterWindow::SetSashPosition(const int position, const bool redraw)
{
m_sashPosition = position;
if ( redraw )
{
SizeWindows();
}
}
// Called when the sash is double-clicked.
// The default behaviour is to remove the sash if the
// minimum pane size is zero.
void wxSplitterWindow::OnDoubleClickSash(int WXUNUSED(x), int WXUNUSED(y) )
{
if ( GetMinimumPaneSize() == 0 )
{
Unsplit();
}
}
// Initialize colours
void wxSplitterWindow::InitColours(void)
{
if ( m_facePen )
delete m_facePen;
if ( m_faceBrush )
delete m_faceBrush;
if ( m_mediumShadowPen )
delete m_mediumShadowPen;
if ( m_darkShadowPen )
delete m_darkShadowPen;
if ( m_lightShadowPen )
delete m_lightShadowPen;
if ( m_hilightPen )
delete m_hilightPen;
// Shadow colours
#if defined(__WIN95__)
// COLORREF ref = ::GetSysColor(COLOR_3DFACE); // Normally light grey
wxColour faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
m_facePen = new wxPen(faceColour, 1, wxSOLID);
m_faceBrush = new wxBrush(faceColour, wxSOLID);
// ref = ::GetSysColor(COLOR_3DSHADOW); // Normally dark grey
wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
m_mediumShadowPen = new wxPen(mediumShadowColour, 1, wxSOLID);
// ref = ::GetSysColor(COLOR_3DDKSHADOW); // Normally black
wxColour darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW));
m_darkShadowPen = new wxPen(darkShadowColour, 1, wxSOLID);
// ref = ::GetSysColor(COLOR_3DLIGHT); // Normally light grey
wxColour lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT));
m_lightShadowPen = new wxPen(lightShadowColour, 1, wxSOLID);
// ref = ::GetSysColor(COLOR_3DHILIGHT); // Normally white
wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
m_hilightPen = new wxPen(hilightColour, 1, wxSOLID);
#else
m_facePen = new wxPen("LIGHT GREY", 1, wxSOLID);
m_faceBrush = new wxBrush("LIGHT GREY", wxSOLID);
m_mediumShadowPen = new wxPen("GREY", 1, wxSOLID);
m_darkShadowPen = new wxPen("BLACK", 1, wxSOLID);
m_lightShadowPen = new wxPen("LIGHT GREY", 1, wxSOLID);
m_hilightPen = new wxPen("WHITE", 1, wxSOLID);
#endif
}

332
src/generic/statusbr.cpp Normal file
View File

@@ -0,0 +1,332 @@
/////////////////////////////////////////////////////////////////////////////
// Name: statusbr.cpp
// Purpose: wxStatusBar class implementation
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "statusbr.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/setup.h"
#include "wx/frame.h"
#include "wx/settings.h"
#include "wx/dcclient.h"
#endif
#include "wx/generic/statusbr.h"
#ifdef __WINDOWS__
#include <windows.h>
#ifdef DrawText
#undef DrawText
#endif
#endif
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow)
BEGIN_EVENT_TABLE(wxStatusBar, wxWindow)
EVT_PAINT(wxStatusBar::OnPaint)
EVT_SYS_COLOUR_CHANGED(wxStatusBar::OnSysColourChanged)
END_EVENT_TABLE()
#endif
// Default status border dimensions
#define wxTHICK_LINE_BORDER 2
#define wxTHICK_LINE_WIDTH 1
wxStatusBar::wxStatusBar(void)
{
m_statusWidths = NULL;
m_statusStrings = NULL;
m_nFields = 0;
m_borderX = wxTHICK_LINE_BORDER;
m_borderY = wxTHICK_LINE_BORDER;
}
wxStatusBar::~wxStatusBar(void)
{
SetFont(wxNullFont);
if ( m_statusWidths )
delete[] m_statusWidths;
if ( m_statusStrings )
delete[] m_statusStrings;
}
bool wxStatusBar::Create(wxWindow *parent, const wxWindowID id,
const wxPoint& pos,
const wxSize& size,
const long style,
const wxString& name)
{
m_statusWidths = NULL;
m_statusStrings = NULL;
m_nFields = 0;
m_borderX = wxTHICK_LINE_BORDER;
m_borderY = wxTHICK_LINE_BORDER;
bool success = wxWindow::Create(parent, id, pos, size, style, name);
// Don't wish this to be found as a child
parent->GetChildren()->DeleteObject(this);
InitColours();
SetFont(m_defaultStatusBarFont);
return success;
}
void wxStatusBar::SetFieldsCount(const int number, const int *widths)
{
m_nFields = number;
if ( m_statusWidths )
delete[] m_statusWidths;
if ( m_statusStrings )
delete[] m_statusStrings;
m_statusStrings = new wxString[number];
int i;
for (i = 0; i < number; i++)
m_statusStrings[i] = "";
if ( widths )
SetStatusWidths(number, widths);
}
void wxStatusBar::SetStatusText(const wxString& text, const int number)
{
if ((number < 0) || (number >= m_nFields))
return;
m_statusStrings[number] = text;
Refresh();
#ifdef __WINDOWS__
// For some reason, this can cause major GDI problems - graphics
// all over the place. E.g. in print previewing.
// ::UpdateWindow((HWND) GetHWND());
#endif
}
wxString wxStatusBar::GetStatusText(const int n) const
{
if ((n < 0) || (n >= m_nFields))
return wxString("");
else
return m_statusStrings[n];
}
void wxStatusBar::SetStatusWidths(const int n, const int *widths_field)
{
// only set status widths, when n == number of statuswindows
if (n == m_nFields)
{
// only set status widths,
// when one window (minimum) is variable (width <= 0)
bool is_variable = FALSE;
int i;
for (i = 0; i < m_nFields; i++)
{
if (widths_field[i] <= 0) is_variable = TRUE;
}
// if there are old widths, delete them
if (m_statusWidths)
delete [] m_statusWidths;
// set widths
m_statusWidths = new int[n];
for (i = 0; i < m_nFields; i++)
{
m_statusWidths[i] = widths_field[i];
}
}
}
void wxStatusBar::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
int i;
if ( GetFont() )
dc.SetFont(*GetFont());
dc.SetBackgroundMode(wxTRANSPARENT);
for ( i = 0; i < m_nFields; i ++ )
DrawField(dc, i);
}
void wxStatusBar::DrawFieldText(wxDC& dc, const int i)
{
int leftMargin = 2;
wxRectangle rect;
GetFieldRect(i, rect);
wxString text(GetStatusText(i));
long x, y;
dc.GetTextExtent(text, &x, &y);
int xpos = rect.x + leftMargin;
int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ;
dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height);
dc.DrawText(text, xpos, ypos);
dc.DestroyClippingRegion();
}
void wxStatusBar::DrawField(wxDC& dc, const int i)
{
wxRectangle rect;
GetFieldRect(i, rect);
// Draw border
// Have grey background, plus 3-d border -
// One black rectangle.
// Inside this, left and top sides - dark grey. Bottom and right -
// white.
dc.SetPen(m_hilightPen);
// Right and bottom white lines
dc.DrawLine(rect.x + rect.width, rect.y,
rect.x + rect.width, rect.y + rect.height);
dc.DrawLine(rect.x + rect.width, rect.y + rect.height,
rect.x, rect.y + rect.height);
dc.SetPen(m_mediumShadowPen);
// Left and top grey lines
dc.DrawLine(rect.x, rect.y + rect.height,
rect.x, rect.y);
dc.DrawLine(rect.x, rect.y,
rect.x + rect.width, rect.y);
DrawFieldText(dc, i);
}
// Get the position and size of the field's internal bounding rectangle
bool wxStatusBar::GetFieldRect(const int n, wxRectangle& rect) const
{
if ((n < 0) || (n >= m_nFields))
return FALSE;
int width, height;
GetClientSize(&width, &height);
int i;
int sum_of_nonvar = 0;
int num_of_var = 0;
bool do_same_width = FALSE;
int fieldWidth = 0;
int fieldPosition = 0;
if (m_statusWidths)
{
// if sum(not variable Windows) > c_width - (20 points per variable_window)
// then do_same_width = TRUE;
for (i = 0; i < m_nFields; i++)
{
if (m_statusWidths[i] > 0) sum_of_nonvar += m_statusWidths[i];
else num_of_var++;
}
if (sum_of_nonvar > (width - 20*num_of_var)) do_same_width = TRUE;
}
else do_same_width = TRUE;
if (do_same_width)
{
for (i = 0; i < m_nFields; i++)
{
fieldWidth = (int)(width/m_nFields);
fieldPosition = i*fieldWidth;
if ( i == n )
break;
}
}
else // no_same_width
{
int *tempwidth = new int[m_nFields];
int temppos = 0;
for (i = 0; i < m_nFields; i++)
{
if (m_statusWidths[i] > 0) tempwidth[i] = m_statusWidths[i];
else tempwidth[i] = (width - sum_of_nonvar) / num_of_var;
}
for (i = 0; i < m_nFields; i++)
{
fieldWidth = tempwidth[i];
fieldPosition = temppos;
temppos += tempwidth[i];
if ( i == n )
break;
}
delete [] tempwidth;
}
rect.x = fieldPosition + wxTHICK_LINE_BORDER;
rect.y = wxTHICK_LINE_BORDER;
rect.width = fieldWidth - 2 * wxTHICK_LINE_BORDER ;
rect.height = height - 2 * wxTHICK_LINE_BORDER ;
return TRUE;
}
// Initialize colours
void wxStatusBar::InitColours(void)
{
// Shadow colours
#if defined(__WIN95__)
wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID);
wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
m_hilightPen = wxPen(hilightColour, 1, wxSOLID);
#else
m_mediumShadowPen = wxPen("GREY", 1, wxSOLID);
m_hilightPen = wxPen("WHITE", 1, wxSOLID);
#endif
m_defaultStatusBarFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
}
// Responds to colour changes, and passes event on to children.
void wxStatusBar::OnSysColourChanged(wxSysColourChangedEvent& event)
{
InitColours();
Refresh();
// Propagate the event to the non-top-level children
wxWindow::OnSysColourChanged(event);
}

1164
src/generic/tabg.cpp Normal file

File diff suppressed because it is too large Load Diff

143
src/generic/textdlgg.cpp Normal file
View File

@@ -0,0 +1,143 @@
/////////////////////////////////////////////////////////////////////////////
// Name: textdlgg.cpp
// Purpose: wxTextEntryDialog
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "textdlgg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/listbox.h"
#include "wx/button.h"
#include "wx/stattext.h"
#include "wx/textctrl.h"
#include "wx/layout.h"
#include "wx/intl.h"
#endif
#include "wx/generic/textdlgg.h"
// wxTextEntryDialog
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
END_EVENT_TABLE()
IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
#endif
extern void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer);
wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& message, const wxString& caption,
const wxString& value, long style, const wxPoint& pos):
wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
{
m_dialogStyle = style;
m_value = value;
wxBeginBusyCursor();
wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
topSizer->SetBorder(10, 10);
wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
messageSizer->SetName("messageSizer");
// bool centre = ((style & wxCENTRE) == wxCENTRE);
wxList messageList;
wxSplitMessage2(message, &messageList, this, messageSizer);
// Insert a spacer
wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 10);
wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxPoint(-1, -1), wxSize(350, -1));
wxRowColSizer *textSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
textSizer->AddSizerChild(textCtrl);
textSizer->SetName("textSizer");
// Create constraints for the text sizer
wxLayoutConstraints *textC = new wxLayoutConstraints;
textC->left.SameAs (messageSizer, wxLeft);
textC->top.Below (spacingSizer);
textSizer->SetConstraints(textC);
// Insert another spacer
wxSpacingSizer *spacingSizer2 = new wxSpacingSizer(topSizer, wxBelow, textSizer, 10);
spacingSizer->SetName("spacingSizer2");
// Insert a sizer for the buttons
wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
buttonSizer->SetName("buttonSizer");
// Specify constraints for the button sizer
wxLayoutConstraints *c = new wxLayoutConstraints;
c->width.AsIs ();
c->height.AsIs ();
c->top.Below (spacingSizer2);
c->centreX.SameAs (textSizer, wxCentreX);
buttonSizer->SetConstraints(c);
wxButton *ok = NULL;
wxButton *cancel = NULL;
if (style & wxOK) {
ok = new wxButton(this, wxID_OK, _("OK"));
buttonSizer->AddSizerChild(ok);
}
if (style & wxCANCEL) {
cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
buttonSizer->AddSizerChild(cancel);
}
if (ok)
{
ok->SetDefault();
ok->SetFocus();
}
Layout();
Centre(wxBOTH);
wxEndBusyCursor();
}
void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
{
wxTextCtrl *textCtrl = (wxTextCtrl *)FindWindow(wxID_TEXT);
if ( textCtrl )
m_value = textCtrl->GetValue();
EndModal(wxID_OK);
}
wxString wxGetTextFromUser(const wxString& message, const wxString& caption,
const wxString& defaultValue, wxWindow *parent,
int x, int y, bool WXUNUSED(centre) )
{
wxTextEntryDialog dialog(parent, message, caption, defaultValue, wxOK|wxCANCEL, wxPoint(x, y));
if (dialog.ShowModal() == wxOK)
return dialog.GetValue();
else
return wxString("");
}

932
src/generic/treectrl.cpp Normal file
View File

@@ -0,0 +1,932 @@
/////////////////////////////////////////////////////////////////////////////
// Name: treectrl.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "treectrl.h"
#endif
#include "wx/treectrl.h"
#include "wx/settings.h"
//-----------------------------------------------------------------------------
// wxTreeItem
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject)
wxTreeItem::wxTreeItem(void)
{
m_mask = 0;
m_itemId = 0;
m_state = 0;
m_stateMask = 0;
m_image = -1;
m_selectedImage = -1;
m_children = 0;
m_data = 0;
};
//-----------------------------------------------------------------------------
// wxTreeEvent
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent,wxCommandEvent)
wxTreeEvent::wxTreeEvent( WXTYPE commandType, int id ) :
wxCommandEvent( commandType, id )
{
m_code = 0;
m_oldItem = 0;
};
//-----------------------------------------------------------------------------
// wxGenericTreeItem
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeItem,wxObject)
wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem *parent )
{
Reset();
m_parent = parent;
m_hasHilight = FALSE;
};
wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem *parent, const wxTreeItem& item, wxDC *dc )
{
Reset();
SetItem( item, dc );
m_parent = parent;
m_hasHilight = FALSE;
};
void wxGenericTreeItem::SetItem( const wxTreeItem &item, wxDC *dc )
{
if ((item.m_mask & wxTREE_MASK_HANDLE) == wxTREE_MASK_HANDLE)
m_itemId = item.m_itemId;
if ((item.m_mask & wxTREE_MASK_STATE) == wxTREE_MASK_STATE)
m_state = item.m_state;
if ((item.m_mask & wxTREE_MASK_TEXT) == wxTREE_MASK_TEXT)
m_text = item.m_text;
if ((item.m_mask & wxTREE_MASK_IMAGE) == wxTREE_MASK_IMAGE)
m_image = item.m_image;
if ((item.m_mask & wxTREE_MASK_SELECTED_IMAGE) == wxTREE_MASK_SELECTED_IMAGE)
m_selectedImage = item.m_selectedImage;
if ((item.m_mask & wxTREE_MASK_CHILDREN) == wxTREE_MASK_CHILDREN)
m_hasChildren = (item.m_children > 0);
if ((item.m_mask & wxTREE_MASK_DATA) == wxTREE_MASK_DATA)
m_data = item.m_data;
long lw = 0;
long lh = 0;
dc->GetTextExtent( m_text, &lw, &lh );
m_width = lw;
m_height = lh;
};
void wxGenericTreeItem::SetText( const wxString &text, wxDC *dc )
{
m_text = text;
long lw = 0;
long lh = 0;
dc->GetTextExtent( m_text, &lw, &lh );
m_width = lw;
m_height = lh;
};
void wxGenericTreeItem::Reset(void)
{
m_itemId = -1;
m_state = 0;
m_text = "";
m_image = -1;
m_selectedImage = -1;
// m_children = 0;
m_hasChildren = FALSE;
m_data = 0;
m_x = 0;
m_y = 0;
m_height = 0;
m_width = 0;
m_xCross = 0;
m_yCross = 0;
m_level = 0;
m_children.DeleteContents( TRUE );
m_parent = NULL;
};
void wxGenericTreeItem::GetItem( wxTreeItem &item ) const
{
if ((item.m_mask & wxTREE_MASK_STATE) == wxTREE_MASK_STATE)
item.m_state = m_state;
if ((item.m_mask & wxTREE_MASK_TEXT) == wxTREE_MASK_TEXT)
item.m_text = m_text;
if ((item.m_mask & wxTREE_MASK_IMAGE) == wxTREE_MASK_IMAGE)
item.m_image = m_image;
if ((item.m_mask & wxTREE_MASK_SELECTED_IMAGE) == wxTREE_MASK_SELECTED_IMAGE)
item.m_selectedImage = m_selectedImage;
if ((item.m_mask & wxTREE_MASK_CHILDREN) == wxTREE_MASK_CHILDREN)
item.m_children = (int)m_hasChildren;
if ((item.m_mask & wxTREE_MASK_DATA) == wxTREE_MASK_DATA)
item.m_data = m_data;
};
bool wxGenericTreeItem::HasChildren(void)
{
return m_hasChildren;
};
bool wxGenericTreeItem::HasPlus(void)
{
return (m_hasChildren && (m_children.Number() == 0));
};
int wxGenericTreeItem::NumberOfVisibleDescendents(void)
{
int ret = m_children.Number();
wxNode *node = m_children.First();
while (node)
{
wxGenericTreeItem *item = (wxGenericTreeItem*)node->Data();
ret += item->NumberOfVisibleDescendents();
node = node->Next();
};
return ret;
};
int wxGenericTreeItem::NumberOfVisibleChildren(void)
{
return m_children.Number();
};
wxGenericTreeItem *wxGenericTreeItem::FindItem( long itemId ) const
{
if (m_itemId == itemId) return (wxGenericTreeItem*)(this);
wxNode *node = m_children.First();
while (node)
{
wxGenericTreeItem *item = (wxGenericTreeItem*)node->Data();
wxGenericTreeItem *res = item->FindItem( itemId );
if (res) return (wxGenericTreeItem*)(res);
node = node->Next();
};
return NULL;
};
void wxGenericTreeItem::AddChild( wxGenericTreeItem *child )
{
m_children.Append( child );
};
void wxGenericTreeItem::SetCross( int x, int y )
{
m_xCross = x;
m_yCross = y;
};
void wxGenericTreeItem::GetSize( int &x, int &y )
{
if (y < m_y + 10) y = m_y +10;
int width = m_x + m_width;
if (width > x) x = width;
wxNode *node = m_children.First();
while (node)
{
wxGenericTreeItem *item = (wxGenericTreeItem*)node->Data();
item->GetSize( x, y );
node = node->Next();
};
};
long wxGenericTreeItem::HitTest( const wxPoint& point, int &flags )
{
if (m_parent && ((point.y > m_y) && (point.y < m_y+m_height)))
{
if ((point.x > m_xCross-5) &&
(point.x < m_xCross+5) &&
(point.y > m_yCross-5) &&
(point.y < m_yCross+5) &&
(m_hasChildren)
)
{
flags = wxTREE_HITTEST_ONITEMBUTTON;
return m_itemId;
};
if ((point.x > m_x) && (point.x < m_x+m_width))
{
flags = wxTREE_HITTEST_ONITEMLABEL;
return m_itemId;
};
if (point.x > m_x)
{
flags = wxTREE_HITTEST_ONITEMRIGHT;
return m_itemId;
};
flags = wxTREE_HITTEST_ONITEMINDENT;
return m_itemId;
}
else
{
wxNode *node = m_children.First();
while (node)
{
wxGenericTreeItem *child = (wxGenericTreeItem*)node->Data();
long res = child->HitTest( point, flags );
if (res != -1) return res;
node = node->Next();
};
};
return -1;
};
void wxGenericTreeItem::PrepareEvent( wxTreeEvent &event )
{
event.m_item.m_itemId = m_itemId;
event.m_item.m_state = m_state;
event.m_item.m_text = m_text;
event.m_item.m_image = m_image;
event.m_item.m_selectedImage = m_selectedImage;
event.m_item.m_children = (int)m_hasChildren;
event.m_item.m_data = m_data;
event.m_oldItem = 0;
event.m_code = 0;
event.m_pointDrag.x = 0;
event.m_pointDrag.y = 0;
};
void wxGenericTreeItem::SendKeyDown( wxWindow *target )
{
wxTreeEvent event( wxEVT_COMMAND_TREE_KEY_DOWN, target->GetId() );
PrepareEvent( event );
event.SetEventObject( target );
target->ProcessEvent( event );
};
void wxGenericTreeItem::SendSelected( wxWindow *target )
{
wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGED, target->GetId() );
PrepareEvent( event );
event.SetEventObject( target );
target->ProcessEvent( event );
};
void wxGenericTreeItem::SendDelete( wxWindow *target )
{
wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM,
target->GetId() );
PrepareEvent( event );
event.SetEventObject( target );
target->ProcessEvent( event );
};
void wxGenericTreeItem::SendExpand( wxWindow *target )
{
wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDED,
target->GetId() );
PrepareEvent( event );
event.SetEventObject( target );
target->ProcessEvent( event );
};
void wxGenericTreeItem::SetHilight( bool set )
{
m_hasHilight = set;
};
bool wxGenericTreeItem::HasHilight(void)
{
return m_hasHilight;
};
//-----------------------------------------------------------------------------
// wxTreeCtrl
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl,wxScrolledWindow
)
BEGIN_EVENT_TABLE(wxTreeCtrl,wxScrolledWindow)
EVT_PAINT (wxTreeCtrl::OnPaint)
EVT_MOUSE_EVENTS (wxTreeCtrl::OnMouse)
EVT_CHAR (wxTreeCtrl::OnChar)
EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus)
EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus)
END_EVENT_TABLE()
wxTreeCtrl::wxTreeCtrl(void)
{
m_current = NULL;
m_anchor = NULL;
m_hasFocus = FALSE;
m_xScroll = 0;
m_yScroll = 0;
m_lastId = 0;
m_lineHeight = 10;
m_indent = 15;
m_isCreated = FALSE;
m_dc = NULL;
m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
};
wxTreeCtrl::wxTreeCtrl(wxWindow *parent, const wxWindowID id,
const wxPoint& pos,
const wxSize& size,
const long style, const wxString& name )
{
m_current = NULL;
m_anchor = NULL;
m_hasFocus = FALSE;
m_xScroll = 0;
m_yScroll = 0;
m_lastId = 0;
m_lineHeight = 10;
m_indent = 15;
m_isCreated = FALSE;
m_dc = NULL;
m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
Create( parent, id, pos, size, style, name );
};
wxTreeCtrl::~wxTreeCtrl(void)
{
if (m_dc) delete m_dc;
};
bool wxTreeCtrl::Create(wxWindow *parent, const wxWindowID id,
const wxPoint& pos,
const wxSize& size,
const long style
, const wxString& name )
{
wxScrolledWindow::Create( parent, id, pos, size, style, name );
SetBackgroundColour( *wxWHITE );
m_dottedPen = wxPen( *wxBLACK, 0, 0 );
return TRUE;
};
int wxTreeCtrl::GetCount(void) const
{
if (!m_anchor) return 0;
return m_anchor->NumberOfVisibleDescendents();
};
long wxTreeCtrl::InsertItem( const long parent, const wxString& label, const int image,
const int selImage, const long WXUNUSED(insertAfter) )
{
wxGenericTreeItem *p = NULL;
if (parent == 0)
{
if (m_anchor) return -1;
}
else
{
p = FindItem( parent );
if (!p) return -1;
};
wxTreeItem item;
m_lastId++;
item.m_mask = wxTREE_MASK_HANDLE;
item.m_itemId = m_lastId;
if (!label.IsNull() || (label == ""))
{
item.m_text = label;
item.m_mask |= wxTREE_MASK_TEXT;
};
if (image >= 0)
{
item.m_image = image;
item.m_mask |= wxTREE_MASK_IMAGE;
};
if (selImage >= 0)
{
item.m_selectedImage = selImage;
item.m_mask |= wxTREE_MASK_SELECTED_IMAGE;
};
wxClientDC dc(this);
wxGenericTreeItem *new_child = new wxGenericTreeItem( p, item, &dc );
if (p)
p->AddChild( new_child );
else
m_anchor = new_child;
if (p)
{
CalculatePositions();
int ch = 0;
GetClientSize( NULL, &ch );
wxRectangle rect;
rect.x = 0; rect.y = 0;
rect.width = 10000; rect.height = ch;
PrepareDC( dc );
if (p->m_children.Number() == 1)
{
rect.y = dc.LogicalToDeviceY( p->m_y );
}
else
{
wxNode *node = p->m_children.Member( new_child )->Previous();
wxGenericTreeItem* last_child = (wxGenericTreeItem*)node->Data();
rect.y = dc.LogicalToDeviceY( last_child->m_y );
};
long doX = 0;
long doY = 0;
dc.GetDeviceOrigin( &doX, &doY );
rect.height = ch-rect.y-doY;
AdjustMyScrollbars();
if (rect.height > 0) Refresh( FALSE, &rect);
}
else
{
AdjustMyScrollbars();
Refresh();
};
return m_lastId;
};
long wxTreeCtrl::InsertItem( const long parent, wxTreeItem &info, const long WXUNUSED(insertAfter) )
{
int oldMask = info.m_mask;
wxGenericTreeItem *p = NULL;
if (parent == 0)
{
if (m_anchor) return -1;
}
else
{
p = FindItem( parent );
if (!p)
{
printf( "TreeItem not found.\n" );
return -1;
};
};
long ret = 0;
if ((info.m_mask & wxTREE_MASK_HANDLE) == 0)
{
m_lastId++;
info.m_itemId = m_lastId;
info.m_mask |= wxTREE_MASK_HANDLE;
ret = m_lastId;
}
else
{
ret = info.m_itemId;
};
wxClientDC dc(this);
wxGenericTreeItem *new_child = new wxGenericTreeItem( p, info, &dc );
if (p)
p->AddChild( new_child );
else
m_anchor = new_child;
if (p)
{
CalculatePositions();
int ch = 0;
GetClientSize( NULL, &ch );
wxRectangle rect;
rect.x = 0; rect.y = 0;
rect.width = 10000; rect.height = ch;
PrepareDC( dc );
if (p->m_children.Number() == 1)
{
rect.y = dc.LogicalToDeviceY( p->m_y );
}
else
{
wxNode *node = p->m_children.Member( new_child )->Previous();
wxGenericTreeItem* last_child = (wxGenericTreeItem*)node->Data();
rect.y = dc.LogicalToDeviceY( last_child->m_y );
};
long doX = 0;
long doY = 0;
dc.GetDeviceOrigin( &doX, &doY );
rect.height = ch-rect.y-doY;
AdjustMyScrollbars();
if (rect.height > 0) Refresh( FALSE, &rect);
}
else
{
AdjustMyScrollbars();
Refresh();
};
info.m_mask = oldMask;
return ret;
};
bool wxTreeCtrl::ExpandItem( const long item, const int action )
{
wxGenericTreeItem *i = FindItem( item );
if (!i) return FALSE;
switch (action)
{
case wxTREE_EXPAND_EXPAND:
{
i->SendExpand( this );
break;
};
case wxTREE_EXPAND_COLLAPSE_RESET:
case wxTREE_EXPAND_COLLAPSE:
{
wxNode *node = i->m_children.First();
while (node)
{
wxGenericTreeItem *child = (wxGenericTreeItem*)node->Data();
child->SendDelete( this );
delete node;
node = i->m_children.First();
};
int cw = 0;
int ch = 0;
GetClientSize( &cw, &ch );
wxRect rect;
rect.x = 0;
rect.width = cw;
wxClientDC dc(this);
PrepareDC(dc);
rect.y = dc.LogicalToDeviceY( i->m_y );
long doY = 0;
dc.GetDeviceOrigin( NULL, &doY );
rect.height = ch-rect.y-doY;
Refresh( TRUE, &rect );
AdjustMyScrollbars();
break;
};
case wxTREE_EXPAND_TOGGLE:
{
if (i->HasPlus())
ExpandItem( item, wxTREE_EXPAND_EXPAND );
else
ExpandItem( item, wxTREE_EXPAND_COLLAPSE );
break;
};
};
return TRUE;
};
bool wxTreeCtrl::DeleteAllItems(void)
{
delete m_anchor;
m_anchor = NULL;
Refresh();
return TRUE;
};
bool wxTreeCtrl::GetItem( wxTreeItem &info ) const
{
wxGenericTreeItem *i = FindItem( info.m_itemId );
if (!i) return FALSE;
i->GetItem( info );
return TRUE;
};
long wxTreeCtrl::GetItemData( const long item ) const
{
wxGenericTreeItem *i = FindItem( item );
if (!i) return 0;
return i->m_data;
};
wxString wxTreeCtrl::GetItemText( const long item ) const
{
wxGenericTreeItem *i = FindItem( item );
if (!i) return "";
return i->m_text;
};
long wxTreeCtrl::GetParent( const long item ) const
{
wxGenericTreeItem *i = FindItem( item );
if (!i) return -1;
i = i->m_parent;
if (!i) return -1;
return i->m_parent->m_itemId;
};
long wxTreeCtrl::GetRootItem(void) const
{
if (m_anchor) return m_anchor->m_itemId;
return -1;
};
long wxTreeCtrl::GetSelection(void) const
{
return 0;
};
bool wxTreeCtrl::SelectItem( const long WXUNUSED(item) ) const
{
return FALSE;
};
bool wxTreeCtrl::ItemHasChildren( const long item ) const
{
wxGenericTreeItem *i = FindItem( item );
if (!i) return FALSE;
return i->m_hasChildren;
};
void wxTreeCtrl::SetIndent( const int indent )
{
m_indent = indent;
Refresh();
};
int wxTreeCtrl::GetIndent(void) const
{
return m_indent;
};
bool wxTreeCtrl::SetItem( wxTreeItem &info )
{
wxGenericTreeItem *i = FindItem( info.m_itemId );
if (!i) return FALSE;
wxClientDC dc(this);
i->SetItem( info, &dc );
return TRUE;
};
bool wxTreeCtrl::SetItemData( const long item, const long data )
{
wxGenericTreeItem *i = FindItem( item );
if (!i) return FALSE;
i->m_data = data;
return TRUE;
};
bool wxTreeCtrl::SetItemText( const long item, const wxString &text )
{
wxGenericTreeItem *i = FindItem( item );
if (!i) return FALSE;
wxClientDC dc(this);
i->SetText( text, &dc );
return TRUE;
};
long wxTreeCtrl::HitTest( const wxPoint& point, int &flags )
{
flags = 0;
if (!m_anchor) return -1;
return m_anchor->HitTest( point, flags );
};
void wxTreeCtrl::AdjustMyScrollbars(void)
{
if (m_anchor)
{
int x = 0;
int y = 0;
m_anchor->GetSize( x, y );
y += 2*m_lineHeight;
int x_pos = GetScrollPos( wxHORIZONTAL );
int y_pos = GetScrollPos( wxVERTICAL );
SetScrollbars( 10, 10, x/10, y/10, x_pos, y_pos );
}
else
{
SetScrollbars( 0, 0, 0, 0 );
};
};
void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, int &y )
{
int horizX = level*m_indent+10;
int oldY = y;
wxNode *node = item->m_children.First();
while (node)
{
wxGenericTreeItem *child = (wxGenericTreeItem *)node->Data();
dc.SetPen( m_dottedPen );
child->SetCross( horizX+15, y );
if (!node->Next())
{
if (level != 0) oldY -= (m_lineHeight-5);
dc.DrawLine( horizX, oldY, horizX, y );
};
child->m_x = horizX+33;
child->m_y = y-m_lineHeight/3;
child->m_height = m_lineHeight;
if (IsExposed( 0, child->m_y-2, 10000, m_lineHeight+4 ))
{
int startX,endX;
if ((node->Previous()) || (level != 0))
startX = horizX; else startX = horizX-10;
if (child->HasChildren())
endX = horizX+10; else endX = horizX+30;
dc.DrawLine( startX, y, endX, y );
if (child->HasChildren())
{
dc.DrawLine( horizX+20, y, horizX+30, y );
dc.SetPen( *wxGREY_PEN );
dc.DrawRectangle( horizX+10, y-4, 11, 9 );
dc.SetPen( *wxBLACK_PEN );
dc.DrawLine( horizX+13, y, horizX+17, y );
if (child->HasPlus())
dc.DrawLine( horizX+15, y-2, horizX+15, y+2 );
};
if (child->HasHilight())
{
dc.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
dc.SetBrush( *m_hilightBrush );
if (m_hasFocus)
dc.SetPen( wxBLACK_PEN );
else
dc.SetPen( wxTRANSPARENT_PEN );
long tw = 0;
long th = 0;
dc.GetTextExtent( child->m_text, &tw, &th );
dc.DrawRectangle( child->m_x-2, child->m_y-2, tw+4, th+4 );
};
dc.DrawText( child->m_text, child->m_x, child->m_y );
if (child->HasHilight())
{
dc.SetTextForeground( *wxBLACK );
dc.SetBrush( *wxWHITE_BRUSH );
dc.SetPen( *wxBLACK_PEN );
};
};
y += m_lineHeight;
if (child->NumberOfVisibleChildren() > 0)
PaintLevel( child, dc, level+1, y );
node = node->Next();
};
};
void wxTreeCtrl::OnPaint( const wxPaintEvent &WXUNUSED(event) )
{
if (!m_anchor) return;
if (!m_dc)
{
m_dc = new wxPaintDC(this);
PrepareDC( *m_dc );
};
m_dc->SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
m_dc->SetPen( m_dottedPen );
m_lineHeight = (int)(m_dc->GetCharHeight() + 4);
int y = m_lineHeight / 2 + 2;
PaintLevel( m_anchor, *m_dc, 0, y );
};
void wxTreeCtrl::OnSetFocus( const wxFocusEvent &WXUNUSED(event) )
{
m_hasFocus = TRUE;
if (m_current) RefreshLine( m_current );
};
void wxTreeCtrl::OnKillFocus( const wxFocusEvent &WXUNUSED(event) )
{
m_hasFocus = FALSE;
if (m_current) RefreshLine( m_current );
};
void wxTreeCtrl::OnChar( wxKeyEvent &event )
{
event.Skip();
};
void wxTreeCtrl::OnMouse( const wxMouseEvent &event )
{
if (!event.LeftDown() &&
!event.LeftDClick()) return;
wxClientDC dc(this);
PrepareDC(dc);
long x = dc.DeviceToLogicalX( (long)event.GetX() );
long y = dc.DeviceToLogicalY( (long)event.GetY() );
int flag = 0;
long id = HitTest( wxPoint(x,y), flag );
if (id == -1) return;
wxGenericTreeItem *item = FindItem( id );
if (!item) return;
if ((flag != wxTREE_HITTEST_ONITEMBUTTON) &&
(flag != wxTREE_HITTEST_ONITEMLABEL)) return;
if (m_current != item)
{
if (m_current)
{
m_current->SetHilight( FALSE );
RefreshLine( m_current );
};
m_current = item;
m_current->SetHilight( TRUE );
RefreshLine( m_current );
m_current->SendSelected( this );
};
if (event.LeftDClick()) m_current->SendKeyDown( this );
if (flag == wxTREE_HITTEST_ONITEMBUTTON)
{
ExpandItem( item->m_itemId, wxTREE_EXPAND_TOGGLE );
return;
};
};
void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, int &y )
{
int horizX = level*m_indent+10;
wxNode *node = item->m_children.First();
while (node)
{
wxGenericTreeItem *child = (wxGenericTreeItem *)node->Data();
dc.SetPen( m_dottedPen );
int startX,endX;
if ((node->Previous()) || (level != 0))
startX = horizX; else startX = horizX-10;
if (child->HasChildren())
endX = horizX+10; else endX = horizX+30;
child->m_x = horizX+33;
child->m_y = y-m_lineHeight/3-2;
child->m_height = m_lineHeight;
y += m_lineHeight;
if (child->NumberOfVisibleChildren() > 0)
CalculateLevel( child, dc, level+1, y );
node = node->Next();
};
};
void wxTreeCtrl::CalculatePositions(void)
{
if (!m_anchor) return;
wxClientDC dc(this);
PrepareDC( dc );
dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
dc.SetPen( m_dottedPen );
m_lineHeight = (int)(dc.GetCharHeight() + 4);
int y = m_lineHeight / 2 + 2;
CalculateLevel( m_anchor, dc, 0, y );
};
wxGenericTreeItem *wxTreeCtrl::FindItem( long itemId ) const
{
if (!m_anchor) return NULL;
return m_anchor->FindItem( itemId );
};
void wxTreeCtrl::RefreshLine( wxGenericTreeItem *item )
{
if (!item) return;
wxClientDC dc(this);
PrepareDC( dc );
wxRect rect;
rect.x = dc.LogicalToDeviceX( item->m_x-2 );
rect.y = dc.LogicalToDeviceY( item->m_y-2 );
rect.width = 1000;
rect.height = dc.GetCharHeight()+4;
Refresh( TRUE, &rect );
};

279
src/gtk/app.cpp Normal file
View File

@@ -0,0 +1,279 @@
/////////////////////////////////////////////////////////////////////////////
// Name: app.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "app.h"
#endif
#include "wx/app.h"
#include "wx/gdicmn.h"
#include "wx/utils.h"
#include "wx/postscrp.h"
#include "wx/intl.h"
#include "wx/log.h"
#include "unistd.h"
#ifdef USE_GDK_IMLIB
#include "gdk_imlib.h"
#endif
//-----------------------------------------------------------------------------
// global data
//-----------------------------------------------------------------------------
wxApp *wxTheApp = NULL;
wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL;
extern wxList wxPendingDelete;
//-----------------------------------------------------------------------------
// local functions
//-----------------------------------------------------------------------------
extern void wxFlushResources(void);
//-----------------------------------------------------------------------------
// global functions
//-----------------------------------------------------------------------------
void wxExit(void)
{
gtk_main_quit();
};
bool wxYield(void)
{
while (gtk_events_pending() > 0) gtk_main_iteration();
return TRUE;
};
//-----------------------------------------------------------------------------
// wxApp
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
gint wxapp_idle_callback( gpointer WXUNUSED(data) )
{
if (wxTheApp) wxTheApp->OnIdle();
usleep( 10000 );
return TRUE;
};
wxApp::wxApp()
{
m_idleTag = 0;
m_topWindow = NULL;
m_exitOnFrameDelete = TRUE;
};
wxApp::~wxApp(void)
{
gtk_idle_remove( m_idleTag );
};
bool wxApp::OnInit(void)
{
return TRUE;
};
bool wxApp::OnInitGui(void)
{
m_idleTag = gtk_idle_add( wxapp_idle_callback, NULL );
return TRUE;
};
int wxApp::OnRun(void)
{
return MainLoop();
};
bool wxApp::OnIdle(void)
{
DeletePendingObjects();
return FALSE;
};
int wxApp::OnExit(void)
{
return 0;
};
int wxApp::MainLoop(void)
{
gtk_main();
return 0;
};
void wxApp::ExitMainLoop(void)
{
gtk_main_quit();
};
bool wxApp::Initialized(void)
{
return m_initialized;
};
bool wxApp::Pending(void)
{
return FALSE;
};
void wxApp::Dispatch(void)
{
};
void wxApp::DeletePendingObjects(void)
{
wxNode *node = wxPendingDelete.First();
while (node)
{
wxObject *obj = (wxObject *)node->Data();
delete obj;
if (wxPendingDelete.Member(obj))
delete node;
node = wxPendingDelete.First();
};
};
wxWindow *wxApp::GetTopWindow(void)
{
if (m_topWindow) return m_topWindow;
wxNode *node = wxTopLevelWindows.First();
if (!node) return NULL;
return (wxWindow*)node->Data();
};
void wxApp::SetTopWindow( wxWindow *win )
{
m_topWindow = win;
};
void wxApp::CommonInit(void)
{
/*
#if USE_RESOURCES
(void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
#endif
*/
wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
wxTheColourDatabase->Initialize();
wxInitializeStockObjects();
// For PostScript printing
#if USE_POSTSCRIPT
wxInitializePrintSetupData();
wxThePrintPaperDatabase = new wxPrintPaperDatabase;
wxThePrintPaperDatabase->CreateDatabase();
#endif
/*
wxBitmap::InitStandardHandlers();
g_globalCursor = new wxCursor;
*/
wxInitializeStockObjects();
};
void wxApp::CommonCleanUp(void)
{
wxDeleteStockObjects();
wxFlushResources();
};
wxLog *wxApp::CreateLogTarget()
{
return new wxLogGui;
}
//-----------------------------------------------------------------------------
// wxEntry
//-----------------------------------------------------------------------------
int wxEntry( int argc, char *argv[] )
{
wxBuffer = new char[BUFSIZ + 512];
wxClassInfo::InitializeClasses();
if (!wxTheApp)
{
if (!wxApp::GetInitializerFunction())
{
printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
return 0;
};
wxAppInitializerFunction app_ini = wxApp::GetInitializerFunction();
wxObject *test_app = app_ini();
wxTheApp = (wxApp*) test_app;
// wxTheApp = (wxApp*)( app_ini() );
};
if (!wxTheApp)
{
printf( "wxWindows error: wxTheApp == NULL\n" );
return 0;
};
// printf( "Programmstart.\n" );
wxTheApp->argc = argc;
wxTheApp->argv = argv;
gtk_init( &argc, &argv );
#ifdef USE_GDK_IMLIB
gdk_imlib_init();
gtk_widget_push_visual(gdk_imlib_get_visual());
gtk_widget_push_colormap(gdk_imlib_get_colormap());
#endif
wxApp::CommonInit();
wxTheApp->OnInitGui();
// Here frames insert themselves automatically
// into wxTopLevelWindows by getting created
// in OnInit().
if (!wxTheApp->OnInit()) return 0;
wxTheApp->m_initialized = (wxTopLevelWindows.Number() > 0);
int retValue = 0;
if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
wxTheApp->DeletePendingObjects();
wxTheApp->OnExit();
wxApp::CommonCleanUp();
return retValue;
};

6
src/gtk/bdiag.xbm Normal file
View File

@@ -0,0 +1,6 @@
#define bdiag_width 16
#define bdiag_height 16
static char bdiag_bits[] = {
0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04,
0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10,
0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01};

293
src/gtk/bitmap.cpp Normal file
View File

@@ -0,0 +1,293 @@
/////////////////////////////////////////////////////////////////////////////
// Name: bitmap.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "bitmap.h"
#endif
#include "wx/bitmap.h"
#include "gdk/gdkprivate.h"
#ifdef USE_GDK_IMLIB
#include "gdk_imlib.h"
#endif
//-----------------------------------------------------------------------------
// wxMask
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMask,wxObject)
wxMask::wxMask(void)
{
m_bitmap = NULL;
};
wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const wxColour& WXUNUSED(colour) )
{
};
wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const int WXUNUSED(paletteIndex) )
{
};
wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap) )
{
};
wxMask::~wxMask(void)
{
#ifdef USE_GDK_IMLIB
// do not delete the mask, gdk_imlib does it for you
#else
if (m_bitmap) gdk_bitmap_unref( m_bitmap );
#endif
};
GdkBitmap *wxMask::GetBitmap(void) const
{
return m_bitmap;
};
//-----------------------------------------------------------------------------
// wxBitmap
//-----------------------------------------------------------------------------
class wxBitmapRefData: public wxObjectRefData
{
public:
wxBitmapRefData(void);
~wxBitmapRefData(void);
GdkPixmap *m_pixmap;
wxMask *m_mask;
int m_width;
int m_height;
int m_bpp;
wxPalette *m_palette;
};
wxBitmapRefData::wxBitmapRefData(void)
{
m_pixmap = NULL;
m_mask = NULL;
m_width = 0;
m_height = 0;
m_bpp = 0;
m_palette = NULL;
};
wxBitmapRefData::~wxBitmapRefData(void)
{
#ifdef USE_GDK_IMLIB
if (m_pixmap) gdk_imlib_free_pixmap( m_pixmap );
#else
if (m_pixmap) gdk_pixmap_unref( m_pixmap );
#endif
if (m_mask) delete m_mask;
if (m_palette) delete m_palette;
};
//-----------------------------------------------------------------------------
#define M_BMPDATA ((wxBitmapRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject)
wxBitmap::wxBitmap(void)
{
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
};
wxBitmap::wxBitmap( const int width, const int height, const int depth )
{
m_refData = new wxBitmapRefData();
M_BMPDATA->m_mask = NULL;
M_BMPDATA->m_pixmap =
gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, width, height, depth );
gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
M_BMPDATA->m_bpp = depth;
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
};
wxBitmap::wxBitmap( char **bits )
{
m_refData = new wxBitmapRefData();
GdkBitmap *mask = NULL;
#ifndef USE_GDK_IMLIB
M_BMPDATA->m_pixmap =
gdk_pixmap_create_from_xpm_d( (GdkWindow*) &gdk_root_parent, &mask, NULL, (gchar **) bits );
#else
M_BMPDATA->m_pixmap = NULL;
int res = gdk_imlib_data_to_pixmap( bits, &M_BMPDATA->m_pixmap, &mask );
#endif
if (mask)
{
M_BMPDATA->m_mask = new wxMask();
M_BMPDATA->m_mask->m_bitmap = mask;
};
gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
M_BMPDATA->m_bpp = 24; // ?
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
};
wxBitmap::wxBitmap( const wxBitmap& bmp )
{
Ref( bmp );
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
};
wxBitmap::wxBitmap( const wxBitmap* bmp )
{
if (bmp) Ref( *bmp );
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
};
wxBitmap::wxBitmap( const wxString &filename, const int type )
{
LoadFile( filename, type );
};
wxBitmap::~wxBitmap(void)
{
if (wxTheBitmapList) wxTheBitmapList->DeleteObject(this);
};
wxBitmap& wxBitmap::operator = ( const wxBitmap& bmp )
{
if (*this == bmp) return (*this);
Ref( bmp );
return *this;
};
bool wxBitmap::operator == ( const wxBitmap& bmp )
{
return m_refData == bmp.m_refData;
};
bool wxBitmap::operator != ( const wxBitmap& bmp )
{
return m_refData != bmp.m_refData;
};
bool wxBitmap::Ok(void) const
{
return m_refData != NULL;
};
int wxBitmap::GetHeight(void) const
{
if (!Ok()) return 0;
return M_BMPDATA->m_height;
};
int wxBitmap::GetWidth(void) const
{
if (!Ok()) return 0;
return M_BMPDATA->m_width;
};
int wxBitmap::GetDepth(void) const
{
if (!Ok()) return 0;
return M_BMPDATA->m_bpp;
};
void wxBitmap::SetHeight( const int height )
{
if (!Ok()) return;
M_BMPDATA->m_height = height;
};
void wxBitmap::SetWidth( const int width )
{
if (!Ok()) return;
M_BMPDATA->m_width = width;
};
void wxBitmap::SetDepth( const int depth )
{
if (!Ok()) return;
M_BMPDATA->m_bpp = depth;
};
wxMask *wxBitmap::GetMask(void) const
{
if (!Ok()) return NULL;
return M_BMPDATA->m_mask;
};
void wxBitmap::SetMask( wxMask *mask )
{
if (!Ok()) return;
if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask;
M_BMPDATA->m_mask = mask;
};
bool wxBitmap::SaveFile( const wxString &WXUNUSED(name), const int WXUNUSED(type),
wxPalette *WXUNUSED(palette) )
{
return FALSE;
};
bool wxBitmap::LoadFile( const wxString &name, const int WXUNUSED(type) )
{
#ifdef USE_GDK_IMLIB
UnRef();
m_refData = new wxBitmapRefData();
M_BMPDATA->m_mask = NULL;
GdkBitmap *mask = NULL;
int res = gdk_imlib_load_file_to_pixmap( WXSTRINGCAST name, &M_BMPDATA->m_pixmap, &mask );
if (res != 1)
{
UnRef();
return FALSE;
};
if (mask)
{
M_BMPDATA->m_mask = new wxMask();
M_BMPDATA->m_mask->m_bitmap = mask;
}
gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
M_BMPDATA->m_bpp = 24; // ?
return TRUE;
#endif
return FALSE;
};
wxPalette *wxBitmap::GetPalette(void) const
{
if (!Ok()) return NULL;
return M_BMPDATA->m_palette;
};
GdkPixmap *wxBitmap::GetPixmap(void) const
{
if (!Ok()) return NULL;
return M_BMPDATA->m_pixmap;
};

132
src/gtk/brush.cpp Normal file
View File

@@ -0,0 +1,132 @@
/////////////////////////////////////////////////////////////////////////////
// Name: brush.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "brush.h"
#endif
#include "wx/brush.h"
//-----------------------------------------------------------------------------
// wxBrush
//-----------------------------------------------------------------------------
class wxBrushRefData: public wxObjectRefData
{
public:
wxBrushRefData(void);
int m_style;
wxBitmap m_stipple;
wxColour m_colour;
};
wxBrushRefData::wxBrushRefData(void)
{
m_style = 0;
};
//-----------------------------------------------------------------------------
#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
wxBrush::wxBrush(void)
{
if (wxTheBrushList) wxTheBrushList->AddBrush( this );
};
wxBrush::wxBrush( const wxColour &colour, const int style )
{
m_refData = new wxBrushRefData();
M_BRUSHDATA->m_style = style;
M_BRUSHDATA->m_colour = colour;
if (wxTheBrushList) wxTheBrushList->AddBrush( this );
};
wxBrush::wxBrush( const wxString &colourName, const int style )
{
m_refData = new wxBrushRefData();
M_BRUSHDATA->m_style = style;
M_BRUSHDATA->m_colour = colourName;
if (wxTheBrushList) wxTheBrushList->AddBrush( this );
};
wxBrush::wxBrush( const wxBitmap &stippleBitmap )
{
m_refData = new wxBrushRefData();
M_BRUSHDATA->m_style = wxSTIPPLE;
M_BRUSHDATA->m_colour = *wxBLACK;
M_BRUSHDATA->m_stipple = stippleBitmap;
if (wxTheBrushList) wxTheBrushList->AddBrush( this );
};
wxBrush::wxBrush( const wxBrush &brush )
{
Ref( brush );
if (wxTheBrushList) wxTheBrushList->AddBrush( this );
};
wxBrush::wxBrush( const wxBrush *brush )
{
if (brush) Ref( *brush );
if (wxTheBrushList) wxTheBrushList->Append( this );
};
wxBrush::~wxBrush(void)
{
if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
};
wxBrush& wxBrush::operator = ( const wxBrush& brush )
{
if (*this == brush) return (*this);
Ref( brush );
return *this;
};
bool wxBrush::operator == ( const wxBrush& brush )
{
return m_refData == brush.m_refData;
};
bool wxBrush::operator != ( const wxBrush& brush )
{
return m_refData != brush.m_refData;
};
bool wxBrush::Ok(void) const
{
return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
};
int wxBrush::GetStyle(void) const
{
return M_BRUSHDATA->m_style;
};
wxColour &wxBrush::GetColour(void) const
{
return M_BRUSHDATA->m_colour;
};
wxBitmap *wxBrush::GetStipple(void) const
{
return &M_BRUSHDATA->m_stipple;
};

89
src/gtk/button.cpp Normal file
View File

@@ -0,0 +1,89 @@
/////////////////////////////////////////////////////////////////////////////
// Name: button.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "button.h"
#endif
#include "wx/button.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class wxButton;
//-----------------------------------------------------------------------------
// wxButton
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), gpointer data )
{
wxButton *button = (wxButton*)data;
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
event.SetEventObject(button);
button->ProcessEvent(event);
};
//-----------------------------------------------------------------------------
wxButton::wxButton(void)
{
};
wxButton::wxButton( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
Create( parent, id, label, pos, size, style, name );
};
bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
m_needParent = TRUE;
wxSize newSize = size;
PreCreation( parent, id, pos, newSize, style, name );
m_label = label;
m_widget = gtk_button_new_with_label( label );
if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y );
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
PostCreation();
Show( TRUE );
return TRUE;
};
void wxButton::SetDefault(void)
{
};
void wxButton::SetLabel( const wxString &label )
{
wxControl::SetLabel( label );
};
wxString wxButton::GetLabel(void) const
{
return wxControl::GetLabel();
};

6
src/gtk/cdiag.xbm Normal file
View File

@@ -0,0 +1,6 @@
#define cdiag_width 16
#define cdiag_height 16
static char cdiag_bits[] = {
0x81, 0x81, 0x42, 0x42, 0x24, 0x24, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24,
0x42, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x42, 0x24, 0x24, 0x18, 0x18,
0x18, 0x18, 0x24, 0x24, 0x42, 0x42, 0x81, 0x81};

84
src/gtk/checkbox.cpp Normal file
View File

@@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////
// Name: checkbox.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "checkbox.h"
#endif
#include "wx/checkbox.h"
//-----------------------------------------------------------------------------
// wxCheckBox
//-----------------------------------------------------------------------------
void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), gpointer data )
{
wxCheckBox *cb = (wxCheckBox*)data;
wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
event.SetInt( cb->GetValue() );
event.SetEventObject(cb);
cb->ProcessEvent(event);
};
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
wxCheckBox::wxCheckBox(void)
{
};
wxCheckBox::wxCheckBox( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
Create( parent, id, label, pos, size, style, name );
};
bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_check_button_new_with_label( label );
wxSize newSize = size;
if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y );
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
PostCreation();
Show( TRUE );
return TRUE;
};
void wxCheckBox::SetValue( const bool state )
{
if (state)
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_ACTIVE );
else
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_NORMAL );
};
bool wxCheckBox::GetValue(void) const
{
GtkToggleButton *tb = GTK_TOGGLE_BUTTON(m_widget);
return tb->active;
};

198
src/gtk/choice.cpp Normal file
View File

@@ -0,0 +1,198 @@
/////////////////////////////////////////////////////////////////////////////
// Name: choice.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "choice.h"
#endif
#include "wx/choice.h"
//-----------------------------------------------------------------------------
// wxChoice
//-----------------------------------------------------------------------------
void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), gpointer data )
{
wxChoice *choice = (wxChoice*)data;
wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId());
event.SetInt( choice->GetSelection() );
wxString tmp( choice->GetStringSelection() );
event.SetString( WXSTRINGCAST(tmp) );
event.SetEventObject(choice);
choice->ProcessEvent(event);
};
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxChoice,wxWindow)
wxChoice::wxChoice(void)
{
};
wxChoice::wxChoice( wxWindow *parent, const wxWindowID id,
const wxPoint &pos, const wxSize &size,
const int n, const wxString choices[],
const long style, const wxString &name )
{
Create( parent, id, pos, size, n, choices, style, name );
};
bool wxChoice::Create( wxWindow *parent, const wxWindowID id,
const wxPoint &pos, const wxSize &size,
const int n, const wxString choices[],
const long style, const wxString &name )
{
m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_option_menu_new();
wxSize newSize = size;
if (newSize.x == -1) newSize.x = 80;
if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y );
GtkWidget *menu;
menu = gtk_menu_new();
for (int i = 0; i < n; i++)
{
GtkWidget *item;
item = gtk_menu_item_new_with_label( choices[i] );
gtk_signal_connect( GTK_OBJECT( item ), "activate",
GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this );
gtk_menu_append( GTK_MENU(menu), item );
gtk_widget_show( item );
};
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
PostCreation();
Show( TRUE );
return TRUE;
};
void wxChoice::Append( const wxString &item )
{
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
GtkWidget *menu_item;
menu_item = gtk_menu_item_new_with_label( item );
gtk_signal_connect( GTK_OBJECT( menu_item ), "activate",
GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this );
gtk_menu_append( GTK_MENU(menu), menu_item );
gtk_widget_show( menu_item );
};
void wxChoice::Clear(void)
{
gtk_option_menu_remove_menu( GTK_OPTION_MENU(m_widget) );
GtkWidget *menu = gtk_menu_new();
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
};
int wxChoice::FindString( const wxString &string ) const
{
// If you read this code once and you think you undestand
// it, then you are very wrong. RR
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
GList *child = menu_shell->children;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL(bin->child);
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
if (string == label->label) return count;
child = child->next;
count++;
};
return -1;
};
int wxChoice::GetColumns(void) const
{
return 1;
};
int wxChoice::GetSelection(void)
{
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
GList *child = menu_shell->children;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
if (!bin->child) return count;
child = child->next;
count++;
};
return -1;
};
wxString wxChoice::GetString( const int n ) const
{
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
GList *child = menu_shell->children;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
if (count == n)
{
GtkLabel *label = GTK_LABEL(bin->child);
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
return label->label;
};
child = child->next;
count++;
};
return "";
};
wxString wxChoice::GetStringSelection(void) const
{
GtkLabel *label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
return label->label;
};
int wxChoice::Number(void) const
{
GtkMenu *menu = GTK_MENU( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
GList *child = menu->children;
while (child)
{
count++;
child = child->next;
};
return count;
};
void wxChoice::SetColumns( const int WXUNUSED(n) )
{
};
void wxChoice::SetSelection( const int n )
{
int tmp = n;
gtk_option_menu_set_history( GTK_OPTION_MENU(m_widget), (gint)tmp );
};
void wxChoice::SetStringSelection( const wxString &string )
{
int n = FindString( string );
if (n != -1) SetSelection( n );
};

225
src/gtk/colour.cpp Normal file
View File

@@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// Name: colour.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "colour.h"
#endif
#include "wx/gdicmn.h"
#ifdef USE_GDK_IMLIB
#include "gdk_imlib.h"
#endif
//-----------------------------------------------------------------------------
// wxColour
//-----------------------------------------------------------------------------
class wxColourRefData: public wxObjectRefData
{
public:
wxColourRefData(void);
~wxColourRefData(void);
void FreeColour(void);
GdkColor m_color;
GdkColormap *m_colormap;
bool m_hasPixel;
friend wxColour;
};
wxColourRefData::wxColourRefData(void)
{
m_color.red = 0;
m_color.green = 0;
m_color.blue = 0;
m_color.pixel = 0;
m_colormap = NULL;
m_hasPixel = FALSE;
};
wxColourRefData::~wxColourRefData(void)
{
FreeColour();
};
void wxColourRefData::FreeColour(void)
{
// if (m_hasPixel) gdk_colors_free( m_colormap, &m_color, 1, 0 );
};
//-----------------------------------------------------------------------------
#define M_COLDATA ((wxColourRefData *)m_refData)
#define SHIFT (8*(sizeof(short int)-sizeof(char)))
IMPLEMENT_DYNAMIC_CLASS(wxColour,wxGDIObject)
wxColour::wxColour(void)
{
};
wxColour::wxColour( char red, char green, char blue )
{
m_refData = new wxColourRefData();
M_COLDATA->m_color.red = ((unsigned short)red) << SHIFT;
M_COLDATA->m_color.green = ((unsigned short)green) << SHIFT;
M_COLDATA->m_color.blue = ((unsigned short)blue) << SHIFT;
M_COLDATA->m_color.pixel = 0;
};
wxColour::wxColour( const wxString &colourName )
{
wxNode *node = NULL;
if ( (wxTheColourDatabase) && (node = wxTheColourDatabase->Find(colourName)) )
{
wxColour *col = (wxColour*)node->Data();
UnRef();
if (col) Ref( *col );
}
else
{
m_refData = new wxColourRefData();
if (!gdk_color_parse( colourName, &M_COLDATA->m_color ))
{
delete m_refData;
m_refData = NULL;
};
};
};
wxColour::wxColour( const wxColour& col )
{
Ref( col );
};
wxColour::wxColour( const wxColour* col )
{
if (col) Ref( *col );
};
wxColour::~wxColour(void)
{
};
wxColour& wxColour::operator = ( const wxColour& col )
{
if (*this == col) return (*this);
Ref( col );
return *this;
};
wxColour& wxColour::operator = ( const wxString& colourName )
{
UnRef();
wxNode *node = NULL;
if ((wxTheColourDatabase) && (node = wxTheColourDatabase->Find(colourName)) )
{
wxColour *col = (wxColour*)node->Data();
if (col) Ref( *col );
}
else
{
m_refData = new wxColourRefData();
if (!gdk_color_parse( colourName, &M_COLDATA->m_color ))
{
delete m_refData;
m_refData = NULL;
};
};
return *this;
};
bool wxColour::operator == ( const wxColour& col )
{
return m_refData == col.m_refData;
};
bool wxColour::operator != ( const wxColour& col)
{
return m_refData != col.m_refData;
};
void wxColour::Set( const unsigned char red, const unsigned char green, const unsigned char blue )
{
UnRef();
m_refData = new wxColourRefData();
M_COLDATA->m_color.red = ((unsigned short)red) << SHIFT;
M_COLDATA->m_color.green = ((unsigned short)green) << SHIFT;
M_COLDATA->m_color.blue = ((unsigned short)blue) << SHIFT;
M_COLDATA->m_color.pixel = 0;
};
unsigned char wxColour::Red(void) const
{
if (!Ok()) return 0;
return (unsigned char)(M_COLDATA->m_color.red >> SHIFT);
};
unsigned char wxColour::Green(void) const
{
if (!Ok()) return 0;
return (unsigned char)(M_COLDATA->m_color.green >> SHIFT);
};
unsigned char wxColour::Blue(void) const
{
if (!Ok()) return 0;
return (unsigned char)(M_COLDATA->m_color.blue >> SHIFT);
};
bool wxColour::Ok(void) const
{
return (m_refData);
};
void wxColour::CalcPixel( GdkColormap *cmap )
{
if (!Ok()) return;
if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap)) return;
M_COLDATA->FreeColour();
#ifdef USE_GDK_IMLIB
int r = M_COLDATA->m_color.red >> SHIFT;
int g = M_COLDATA->m_color.green >> SHIFT;
int b = M_COLDATA->m_color.blue >> SHIFT;
M_COLDATA->m_hasPixel = TRUE;
M_COLDATA->m_color.pixel = gdk_imlib_best_color_match( &r, &g, &b );
#else
M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
#endif
M_COLDATA->m_colormap = cmap;
};
int wxColour::GetPixel(void)
{
if (!Ok()) return 0;
return M_COLDATA->m_color.pixel;
};
GdkColor *wxColour::GetColor(void)
{
if (!Ok()) return NULL;
return &M_COLDATA->m_color;
};

51
src/gtk/control.cpp Normal file
View File

@@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////
// Name: control.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "control.h"
#endif
#include "wx/control.h"
//-----------------------------------------------------------------------------
// wxControl
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxControl,wxWindow)
wxControl::wxControl(void)
{
m_label = "";
m_needParent = TRUE;
};
wxControl::wxControl( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name ) :
wxWindow( parent, id, pos, size, style, name )
{
};
void wxControl::Command( wxCommandEvent &WXUNUSED(event) )
{
};
void wxControl::SetLabel( const wxString &label )
{
m_label = label;
};
wxString wxControl::GetLabel(void) const
{
return m_label;
};

6
src/gtk/cross.xbm Normal file
View File

@@ -0,0 +1,6 @@
#define cross_width 15
#define cross_height 15
static char cross_bits[] = {
0x84, 0x10, 0x84, 0x10, 0xff, 0x7f, 0x84, 0x10, 0x84, 0x10, 0x84, 0x10,
0x84, 0x10, 0xff, 0x7f, 0x84, 0x10, 0x84, 0x10, 0x84, 0x10, 0x84, 0x10,
0xff, 0x7f, 0x84, 0x10, 0x84, 0x10};

173
src/gtk/cursor.cpp Normal file
View File

@@ -0,0 +1,173 @@
/////////////////////////////////////////////////////////////////////////////
// Name: cursor.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "cursor.h"
#endif
#include "wx/cursor.h"
//-----------------------------------------------------------------------------
// wxCursor
//-----------------------------------------------------------------------------
class wxCursorRefData: public wxObjectRefData
{
public:
wxCursorRefData(void);
~wxCursorRefData(void);
GdkCursor *m_cursor;
};
wxCursorRefData::wxCursorRefData(void)
{
m_cursor = NULL;
};
wxCursorRefData::~wxCursorRefData(void)
{
if (m_cursor) gdk_cursor_destroy( m_cursor );
};
//-----------------------------------------------------------------------------
#define M_CURSORDATA ((wxCursorRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
wxCursor::wxCursor(void)
{
};
wxCursor::wxCursor( const int cursorId )
{
m_refData = new wxCursorRefData();
GdkCursorType gdk_cur = GDK_LEFT_PTR;
switch (cursorId)
{
case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break;
case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break;
case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break;
case wxCURSOR_SIZENS: gdk_cur = GDK_SB_V_DOUBLE_ARROW; break;
case wxCURSOR_WAIT: gdk_cur = GDK_WATCH; break;
case wxCURSOR_WATCH: gdk_cur = GDK_WATCH; break;
case wxCURSOR_SIZING: gdk_cur = GDK_SIZING; break;
case wxCURSOR_SPRAYCAN: gdk_cur = GDK_SPRAYCAN; break;
case wxCURSOR_IBEAM: gdk_cur = GDK_XTERM; break;
case wxCURSOR_PENCIL: gdk_cur = GDK_PENCIL; break;
case wxCURSOR_NO_ENTRY: gdk_cur = GDK_PIRATE; break;
};
M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur );
/*
do that yourself
wxCURSOR_BULLSEYE,
wxCURSOR_CHAR,
wxCURSOR_LEFT_BUTTON,
wxCURSOR_MAGNIFIER,
wxCURSOR_MIDDLE_BUTTON,
wxCURSOR_NO_ENTRY,
wxCURSOR_PAINT_BRUSH,
wxCURSOR_POINT_LEFT,
wxCURSOR_POINT_RIGHT,
wxCURSOR_QUESTION_ARROW,
wxCURSOR_RIGHT_BUTTON,
wxCURSOR_SIZENESW,
wxCURSOR_SIZENS,
wxCURSOR_SIZENWSE,
wxCURSOR_SIZEWE,
wxCURSOR_BLANK
,
wxCURSOR_CROSS_REVERSE,
wxCURSOR_DOUBLE_ARROW,
wxCURSOR_BASED_ARROW_UP,
wxCURSOR_BASED_ARROW_DOWN
*/
};
wxCursor::wxCursor( const wxCursor &cursor )
{
Ref( cursor );
};
wxCursor::wxCursor( const wxCursor *cursor )
{
UnRef();
if (cursor) Ref( *cursor );
};
wxCursor::~wxCursor(void)
{
};
wxCursor& wxCursor::operator = ( const wxCursor& cursor )
{
if (*this == cursor) return (*this);
Ref( cursor );
return *this;
};
bool wxCursor::operator == ( const wxCursor& cursor )
{
return m_refData == cursor.m_refData;
};
bool wxCursor::operator != ( const wxCursor& cursor )
{
return m_refData != cursor.m_refData;
};
bool wxCursor::Ok(void) const
{
return TRUE;
};
GdkCursor *wxCursor::GetCursor(void) const
{
return M_CURSORDATA->m_cursor;
};
//-----------------------------------------------------------------------------
// busy cursor routines
//-----------------------------------------------------------------------------
bool g_isBusy = FALSE;
void wxEndBusyCursor(void)
{
g_isBusy = FALSE;
};
void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) )
{
g_isBusy = TRUE;
};
bool wxIsBusy(void)
{
return g_isBusy;
};
void wxSetCursor( const wxCursor& cursor )
{
extern wxCursor *g_globalCursor;
if (g_globalCursor) (*g_globalCursor) = cursor;
if (cursor.Ok()) {};
};

705
src/gtk/data.cpp Normal file
View File

@@ -0,0 +1,705 @@
/////////////////////////////////////////////////////////////////////////////
// Name: data.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// #pragma implementation
#endif
#include "wx/wx.h"
#define _MAXPATHLEN 500
// Used for X resources
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
wxList wxResourceCache(wxKEY_STRING);
XrmDatabase wxResourceDatabase;
// Useful buffer, initialized in wxCommonInit
char *wxBuffer = NULL;
// Windows List
wxList wxTopLevelWindows;
// List of windows pending deletion
wxList wxPendingDelete;
// Current cursor, in order to hang on to
// cursor handle when setting the cursor globally
wxCursor *g_globalCursor = NULL;
// Don't allow event propagation during drag
bool g_blockEventsOnDrag = FALSE;
// Message Strings for Internationalization
char **wx_msg_str = (char**)NULL;
// Custom OS version, as optionally placed in wx.ini/.wxrc
// Currently this can be Win95, Windows, Win32s, WinNT.
// For some systems, you can't tell until run-time what services you
// have. See wxGetOsVersion, which uses this string if present.
char *wxOsVersion = NULL;
// For printing several pages
int wxPageNumber;
wxPrintPaperDatabase* wxThePrintPaperDatabase = NULL;
// GDI Object Lists
wxBrushList *wxTheBrushList = NULL;
wxPenList *wxThePenList = NULL;
wxFontList *wxTheFontList = NULL;
wxColourDatabase *wxTheColourDatabase = NULL;
wxBitmapList *wxTheBitmapList = NULL;
// X only font names
wxFontNameDirectory wxTheFontNameDirectory;
// Stock objects
wxFont *wxNORMAL_FONT;
wxFont *wxSMALL_FONT;
wxFont *wxITALIC_FONT;
wxFont *wxSWISS_FONT;
wxPen *wxRED_PEN;
wxPen *wxCYAN_PEN;
wxPen *wxGREEN_PEN;
wxPen *wxBLACK_PEN;
wxPen *wxWHITE_PEN;
wxPen *wxTRANSPARENT_PEN;
wxPen *wxBLACK_DASHED_PEN;
wxPen *wxGREY_PEN;
wxPen *wxMEDIUM_GREY_PEN;
wxPen *wxLIGHT_GREY_PEN;
wxBrush *wxBLUE_BRUSH;
wxBrush *wxGREEN_BRUSH;
wxBrush *wxWHITE_BRUSH;
wxBrush *wxBLACK_BRUSH;
wxBrush *wxTRANSPARENT_BRUSH;
wxBrush *wxCYAN_BRUSH;
wxBrush *wxRED_BRUSH;
wxBrush *wxGREY_BRUSH;
wxBrush *wxMEDIUM_GREY_BRUSH;
wxBrush *wxLIGHT_GREY_BRUSH;
wxColour *wxBLACK;
wxColour *wxWHITE;
wxColour *wxGREY; // Robert Roebling
wxColour *wxRED;
wxColour *wxBLUE;
wxColour *wxGREEN;
wxColour *wxCYAN;
wxColour *wxLIGHT_GREY;
wxCursor *wxSTANDARD_CURSOR = NULL;
wxCursor *wxHOURGLASS_CURSOR = NULL;
wxCursor *wxCROSS_CURSOR = NULL;
// 'Null' objects
wxBitmap wxNullBitmap;
wxIcon wxNullIcon;
wxCursor wxNullCursor;
wxPen wxNullPen;
wxBrush wxNullBrush;
wxFont wxNullFont;
wxColour wxNullColour;
wxPalette wxNullPalette;
// Default window names
const char *wxButtonNameStr = "button";
const char *wxCanvasNameStr = "canvas";
const char *wxCheckBoxNameStr = "check";
const char *wxChoiceNameStr = "choice";
const char *wxComboBoxNameStr = "comboBox";
const char *wxDialogNameStr = "dialog";
const char *wxFrameNameStr = "frame";
const char *wxGaugeNameStr = "gauge";
const char *wxStaticBoxNameStr = "groupBox";
const char *wxListBoxNameStr = "listBox";
const char *wxStaticTextNameStr = "message";
const char *wxStaticBitmapNameStr = "message";
const char *wxMultiTextNameStr = "multitext";
const char *wxPanelNameStr = "panel";
const char *wxRadioBoxNameStr = "radioBox";
const char *wxRadioButtonNameStr = "radioButton";
const char *wxBitmapRadioButtonNameStr = "radioButton";
const char *wxScrollBarNameStr = "scrollBar";
const char *wxSliderNameStr = "slider";
const char *wxStaticNameStr = "static";
const char *wxTextCtrlWindowNameStr = "textWindow";
const char *wxTextCtrlNameStr = "text";
const char *wxVirtListBoxNameStr = "virtListBox";
const char *wxButtonBarNameStr = "buttonbar";
const char *wxEnhDialogNameStr = "Shell";
const char *wxToolBarNameStr = "toolbar";
const char *wxStatusLineNameStr = "status_line";
const char *wxEmptyString = "";
const char *wxGetTextFromUserPromptStr = "Input Text";
const char *wxMessageBoxCaptionStr = "Message";
const char *wxFileSelectorPromptStr = "Select a file";
const char *wxFileSelectorDefaultWildcardStr = "*.*";
const char *wxInternalErrorStr = "wxWindows Internal Error";
const char *wxFatalErrorStr = "wxWindows Fatal Error";
// See wx/utils.h
const char *wxFloatToStringStr = "%.2f";
const char *wxDoubleToStringStr = "%.2f";
#ifdef wx_msw
const char *wxUserResourceStr = "TEXT";
#endif
#if USE_SHARED_LIBRARY
/*
* For wxWindows to be made into a dynamic library (e.g. Sun),
* all IMPLEMENT_... macros must be in one place.
* But normally, the definitions are in the appropriate places.
*/
// Hand-coded IMPLEMENT... macro for wxObject (define static data)
wxClassInfo wxObject::classwxObject("wxObject", NULL, NULL, sizeof(wxObject), NULL);
wxClassInfo *wxClassInfo::first = NULL;
#include "wx/button.h"
#include "wx/bmpbuttn.h"
IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
#include "wx/checkbox.h"
IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
#include "wx/choice.h"
IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
#if USE_CLIPBOARD
#include "wx/clipbrd.h"
IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject)
#endif
#if USE_COMBOBOX
#include "wx/combobox.h"
IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
#endif
#include "wx/dc.h"
#include "wx/dcmemory.h"
#include "wx/dcclient.h"
#include "wx/dcscreen.h"
IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
#if defined(wx_msw)
#include "wx/dcprint.h"
IMPLEMENT_CLASS(wxPrinterDC, wxDC)
#endif
#include "wx/dialog.h"
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxWindow)
#include "wx/frame.h"
IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
#include "wx/mdi.h"
IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
#include "wx/cmndata.h"
IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
#include "wx/colordlg.h"
#include "wx/fontdlg.h"
#if !defined(wx_msw) || USE_GENERIC_DIALOGS_IN_MSW
#include "wx/generic/colordlg.h"
#include "wx/generic/fontdlg.h"
IMPLEMENT_DYNAMIC_CLASS(wxGenericColourDialog, wxDialog)
IMPLEMENT_DYNAMIC_CLASS(wxGenericFontDialog, wxDialog)
#endif
// X defines wxColourDialog to be wxGenericColourDialog
#ifndef wx_x
IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
#endif
#include "wx/gdicmn.h"
#include "wx/pen.h"
#include "wx/brush.h"
#include "wx/font.h"
#include "wx/palette.h"
#include "wx/icon.h"
#include "wx/cursor.h"
IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
IMPLEMENT_CLASS(wxColourDatabase, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList)
#if (!USE_TYPEDEFS)
IMPLEMENT_DYNAMIC_CLASS(wxPoint, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxIntPoint, wxObject)
#endif
#if defined(wx_x) || (defined(wx_msw) && USE_PORTABLE_FONTS_IN_MSW)
IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
#endif
#include "wx/hash.h"
IMPLEMENT_DYNAMIC_CLASS(wxHashTable, wxObject)
#include "wx/help.h"
IMPLEMENT_DYNAMIC_CLASS(wxHelpInstance, wxClient)
IMPLEMENT_CLASS(wxHelpConnection, wxConnection)
#include "wx/list.h"
IMPLEMENT_DYNAMIC_CLASS(wxNode, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxList, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxStringList, wxList)
#if USE_PRINTING_ARCHITECTURE
#include "wx/print.h"
IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
IMPLEMENT_DYNAMIC_CLASS(wxPrinterBase, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter, wxPrinterBase)
IMPLEMENT_DYNAMIC_CLASS(wxWindowsPrinter, wxPrinterBase)
IMPLEMENT_ABSTRACT_CLASS(wxPrintout, wxObject)
IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow)
IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow)
IMPLEMENT_CLASS(wxPreviewFrame, wxFrame)
IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject)
IMPLEMENT_CLASS(wxPostScriptPrintPreview, wxPrintPreviewBase)
IMPLEMENT_CLASS(wxWindowsPrintPreview, wxPrintPreviewBase)
IMPLEMENT_CLASS(wxGenericPrintDialog, wxDialog)
IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
#endif
#if USE_POSTSCRIPT
#include "wx/postscrp.h"
IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList)
#endif
#if USE_WX_RESOURCES
#include "wx/resource.h"
IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable)
#endif
#include "wx/event.h"
IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxEvent)
#include "wx/utils.h"
IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxList)
IMPLEMENT_DYNAMIC_CLASS(wxRect, wxObject)
#if USE_TIMEDATE
#include "wx/date.h"
IMPLEMENT_DYNAMIC_CLASS(wxDate, wxObject)
#endif
#if USE_DOC_VIEW_ARCHITECTURE
#include "wx/docview.h"
//IMPLEMENT_ABSTRACT_CLASS(wxDocItem, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler)
IMPLEMENT_CLASS(wxDocChildFrame, wxFrame)
IMPLEMENT_CLASS(wxDocParentFrame, wxFrame)
#if USE_PRINTING_ARCHITECTURE
IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout)
#endif
IMPLEMENT_CLASS(wxCommand, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject)
#endif
#if USE_CONSTRAINTS
#include "wx/layout.h"
IMPLEMENT_DYNAMIC_CLASS(wxIndividualLayoutConstraint, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxLayoutConstraints, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxSizer, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxRowColSizer, wxSizer)
#endif
#if USE_TOOLBAR
#include "wx/tbarbase.h"
IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxToolBarBase, wxControl)
#include "wx/tbarsmpl.h"
IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple, wxToolBarBase)
#ifdef wx_msw
#include "wx/tbarmsw.h"
IMPLEMENT_DYNAMIC_CLASS(wxToolBarMSW, wxToolBarBase)
#include "wx/tbar95.h"
IMPLEMENT_DYNAMIC_CLASS(wxToolBar95, wxToolBarBase)
#endif
#endif
#include "wx/statusbr.h"
IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow)
BEGIN_EVENT_TABLE(wxStatusBar, wxWindow)
EVT_PAINT(wxStatusBar::OnPaint)
EVT_SYS_COLOUR_CHANGED(wxStatusBar::OnSysColourChanged)
END_EVENT_TABLE()
#if USE_TIMEDATE
#include "wx/time.h"
IMPLEMENT_DYNAMIC_CLASS(wxTime, wxObject)
#endif
#if !USE_GNU_WXSTRING
#include "wx/string.h"
IMPLEMENT_DYNAMIC_CLASS(wxString, wxObject)
#endif
#ifdef wx_motif
IMPLEMENT_DYNAMIC_CLASS(wxXColormap, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxXFont, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxXCursor, wxObject)
#endif
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
// This will presumably be implemented on other platforms too
#ifdef wx_msw
IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler, wxBitmapHandler)
IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler, wxBitmapHandler)
IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler, wxBitmapHandler)
IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxBitmapHandler)
IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxBitmapHandler)
#endif
#include "wx/statbox.h"
IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
#if USE_IPC
#include "wx/dde.h"
IMPLEMENT_ABSTRACT_CLASS(wxDDEObject, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxDDEServer, wxDDEObject)
IMPLEMENT_DYNAMIC_CLASS(wxDDEClient, wxDDEObject)
IMPLEMENT_CLASS(wxDDEConnection, wxObject)
#endif
IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
#include "wx/listbox.h"
IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
#include "wx/menu.h"
IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxWindow)
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxWindow)
#include "wx/stattext.h"
#include "wx/statbmp.h"
IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
#if USE_METAFILE
#include "wx/metafile.h"
IMPLEMENT_DYNAMIC_CLASS(wxMetaFile, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxMetaFileDC, wxDC)
#endif
#include "wx/radiobox.h"
#include "wx/radiobut.h"
IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
// IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
#include "wx/scrolbar.h"
IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
#if WXWIN_COMPATIBILITY
BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
EVT_SCROLL(wxScrollBar::OnScroll)
END_EVENT_TABLE()
#endif
#include "wx/slider.h"
IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
#if WXWIN_COMPATIBILITY
BEGIN_EVENT_TABLE(wxSlider, wxControl)
EVT_SCROLL(wxSlider::OnScroll)
END_EVENT_TABLE()
#endif
#include "wx/timer.h"
IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
#include "wx/textctrl.h"
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
#include "wx/window.h"
IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
#include "wx/scrolwin.h"
IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxWindow)
#include "wx/panel.h"
IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
#include "wx/msgbxdlg.h"
#include "wx/textdlg.h"
#include "wx/filedlg.h"
#include "wx/dirdlg.h"
#include "wx/choicdlg.h"
#if !defined(wx_msw) || USE_GENERIC_DIALOGS_IN_MSW
#include "wx/generic/msgdlgg.h"
IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
#endif
IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
IMPLEMENT_CLASS(wxSingleChoiceDialog, wxDialog)
IMPLEMENT_CLASS(wxFileDialog, wxDialog)
IMPLEMENT_CLASS(wxDirDialog, wxDialog)
#ifdef wx_msw
IMPLEMENT_CLASS(wxMessageDialog)
#endif
#if USE_GAUGE
#ifdef wx_motif
#include "../../contrib/xmgauge/gauge.h"
#endif
#include "wx_gauge.h"
IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
#endif
#include "wx/grid.h"
IMPLEMENT_DYNAMIC_CLASS(wxGenericGrid, wxPanel)
///// Event tables (also must be in one, statically-linked file for shared libraries)
// This is the base, wxEvtHandler 'bootstrap' code which is expanded manually here
const wxEventTable *wxEvtHandler::GetEventTable() const { return &wxEvtHandler::sm_eventTable; }
const wxEventTable wxEvtHandler::sm_eventTable =
{ NULL, &wxEvtHandler::sm_eventTableEntries[0] };
const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { { 0, 0, 0, NULL } };
BEGIN_EVENT_TABLE(wxFrame, wxWindow)
EVT_ACTIVATE(wxFrame::OnActivate)
EVT_SIZE(wxFrame::OnSize)
EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
EVT_IDLE(wxFrame::OnIdle)
EVT_CLOSE(wxFrame::OnCloseWindow)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxDialog, wxPanel)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_CHAR_HOOK(wxDialog::OnCharHook)
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
EVT_CHAR(wxWindow::OnChar)
EVT_SIZE(wxWindow::Size)
EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
EVT_INIT_DIALOG(wxWindow::OnInitDialog)
EVT_IDLE(wxWindow::OnIdle)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxScrolledWindow, wxWindow)
EVT_SCROLL(wxScrolledWindow::OnScroll)
EVT_SIZE(wxScrolledWindow::OnSize)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxPanel, wxWindow)
EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
EVT_CHAR(wxTextCtrl::OnChar)
EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground)
END_EVENT_TABLE()
#ifdef wx_msw
BEGIN_EVENT_TABLE(wxMDIParentWindow, wxFrame)
EVT_SIZE(wxMDIParentWindow::OnSize)
EVT_ACTIVATE(wxMDIParentWindow::OnActivate)
EVT_SYS_COLOUR_CHANGED(wxMDIParentWindow::OnSysColourChanged)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
EVT_SCROLL(wxMDIClientWindow::OnScroll)
END_EVENT_TABLE()
#endif
BEGIN_EVENT_TABLE(wxToolBarBase, wxControl)
EVT_SCROLL(wxToolBarBase::OnScroll)
EVT_SIZE(wxToolBarBase::OnSize)
EVT_IDLE(wxToolBarBase::OnIdle)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxToolBarSimple, wxToolBarBase)
EVT_SIZE(wxToolBarSimple::OnSize)
EVT_PAINT(wxToolBarSimple::OnPaint)
EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus)
EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent)
END_EVENT_TABLE()
#ifdef wx_msw
BEGIN_EVENT_TABLE(wxToolBarMSW, wxToolBarBase)
EVT_SIZE(wxToolBarMSW::OnSize)
EVT_PAINT(wxToolBarMSW::OnPaint)
EVT_MOUSE_EVENTS(wxToolBarMSW::OnMouseEvent)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxToolBar95, wxToolBarBase)
EVT_SIZE(wxToolBar95::OnSize)
EVT_PAINT(wxToolBar95::OnPaint)
EVT_KILL_FOCUS(wxToolBar95::OnKillFocus)
EVT_MOUSE_EVENTS(wxToolBar95::OnMouseEvent)
EVT_SYS_COLOUR_CHANGED(wxToolBar95::OnSysColourChanged)
END_EVENT_TABLE()
#endif
BEGIN_EVENT_TABLE(wxGenericGrid, wxPanel)
EVT_SIZE(wxGenericGrid::OnSize)
EVT_PAINT(wxGenericGrid::OnPaint)
EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent)
EVT_TEXT(wxGRID_TEXT_CTRL, wxGenericGrid::OnText)
EVT_COMMAND_SCROLL(wxGRID_HSCROLL, wxGenericGrid::OnGridScroll)
EVT_COMMAND_SCROLL(wxGRID_VSCROLL, wxGenericGrid::OnGridScroll)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxControl, wxWindow)
EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
END_EVENT_TABLE()
#if !defined(wx_msw) || USE_GENERIC_DIALOGS_IN_MSW
BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxGenericColourDialog, wxDialog)
EVT_BUTTON(wxID_ADD_CUSTOM, wxGenericColourDialog::OnAddCustom)
EVT_SLIDER(wxID_RED_SLIDER, wxGenericColourDialog::OnRedSlider)
EVT_SLIDER(wxID_GREEN_SLIDER, wxGenericColourDialog::OnGreenSlider)
EVT_SLIDER(wxID_BLUE_SLIDER, wxGenericColourDialog::OnBlueSlider)
EVT_PAINT(wxGenericColourDialog::OnPaint)
EVT_MOUSE_EVENTS(wxGenericColourDialog::OnMouseEvent)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxGenericFontDialog, wxDialog)
EVT_CHECKBOX(wxID_FONT_UNDERLINE, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_STYLE, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_WEIGHT, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_FAMILY, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_COLOUR, wxGenericFontDialog::OnChangeFont)
EVT_CHOICE(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeFont)
EVT_PAINT(wxGenericFontDialog::OnPaint)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxDialog)
EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK)
EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup)
EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange)
END_EVENT_TABLE()
#endif
BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxSingleChoiceDialog, wxDialog)
EVT_BUTTON(wxID_OK, wxSingleChoiceDialog::OnOK)
END_EVENT_TABLE()
#include "wx/prntbase.h"
BEGIN_EVENT_TABLE(wxPrintAbortDialog, wxDialog)
EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxPreviewControlBar, wxWindow)
EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnClose)
EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint)
EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPrevious)
EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNext)
EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom)
END_EVENT_TABLE()
#endif
const wxSize wxDefaultSize(-1, -1);
const wxPoint wxDefaultPosition(-1, -1);

370
src/gtk/dc.cpp Normal file
View File

@@ -0,0 +1,370 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dc.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dc.h"
#endif
#include "wx/dc.h"
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
#define mm2inches 0.0393700787402
#define inches2mm 25.4
#define mm2twips 56.6929133859
#define twips2mm 0.0176388888889
#define mm2pt 2.83464566929
#define pt2mm 0.352777777778
//-----------------------------------------------------------------------------
// wxDC
//-----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDC,wxObject)
wxDC::wxDC(void)
{
m_ok = FALSE;
m_optimize = FALSE;
m_autoSetting = FALSE;
m_colour = TRUE;
m_clipping = FALSE;
m_mm_to_pix_x = 1.0;
m_mm_to_pix_y = 1.0;
m_logicalOriginX = 0;
m_logicalOriginY = 0;
m_deviceOriginX = 0;
m_deviceOriginY = 0;
m_internalDeviceOriginX = 0;
m_internalDeviceOriginY = 0;
m_externalDeviceOriginX = 0;
m_externalDeviceOriginY = 0;
m_logicalScaleX = 1.0;
m_logicalScaleY = 1.0;
m_userScaleX = 1.0;
m_userScaleY = 1.0;
m_scaleX = 1.0;
m_scaleY = 1.0;
m_mappingMode = MM_TEXT;
m_needComputeScaleX = FALSE;
m_needComputeScaleY = FALSE;
m_signX = 1; // default x-axis left to right
m_signY = 1; // default y-axis top down
m_maxX = m_maxY = -100000;
m_minY = m_minY = 100000;
m_logicalFunction = wxCOPY;
// m_textAlignment = wxALIGN_TOP_LEFT;
m_backgroundMode = wxTRANSPARENT;
m_textForegroundColour = *wxBLACK;
m_textBackgroundColour = *wxWHITE;
m_pen = *wxBLACK_PEN;
m_font = *wxNORMAL_FONT;
m_brush = *wxTRANSPARENT_BRUSH;
m_backgroundBrush = *wxWHITE_BRUSH;
// m_palette = wxAPP_COLOURMAP;
};
wxDC::~wxDC(void)
{
};
void wxDC::DrawArc( long WXUNUSED(x1), long WXUNUSED(y1), long WXUNUSED(x2), long WXUNUSED(y2),
double WXUNUSED(xc), double WXUNUSED(yc) )
{
};
void wxDC::DrawIcon( const wxIcon &WXUNUSED(icon), long WXUNUSED(x), long WXUNUSED(y), bool WXUNUSED(useMask) )
{
};
void wxDC::DrawPoint( wxPoint& point )
{
DrawPoint( point.x, point.y );
};
void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle )
{
int n = list->Number();
wxPoint *points = new wxPoint[n];
int i = 0;
for( wxNode *node = list->First(); node; node = node->Next() )
{
wxPoint *point = (wxPoint *)node->Data();
points[i].x = point->x;
points[i++].y = point->y;
};
DrawPolygon( n, points, xoffset, yoffset, fillStyle );
delete[] points;
};
void wxDC::DrawLines( wxList *list, long xoffset, long yoffset )
{
int n = list->Number();
wxPoint *points = new wxPoint[n];
int i = 0;
for( wxNode *node = list->First(); node; node = node->Next() )
{
wxPoint *point = (wxPoint *)node->Data();
points[i].x = point->x;
points[i++].y = point->y;
};
DrawLines( n, points, xoffset, yoffset );
delete []points;
};
void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 )
{
wxList list;
list.DeleteContents(TRUE);
list.Append( new wxPoint(x1, y1) );
list.Append( new wxPoint(x2, y2) );
list.Append( new wxPoint(x3, y3) );
DrawSpline(&list);
};
void wxDC::DrawSpline( wxList *points )
{
DrawOpenSpline( points );
};
void wxDC::DrawSpline( int n, wxPoint points[] )
{
wxList list;
for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] );
DrawSpline( &list );
};
void wxDC::SetClippingRegion( long x, long y, long width, long height )
{
m_clipping = TRUE;
m_clipX1 = x;
m_clipY1 = y;
m_clipX2 = x + width;
m_clipY2 = y + height;
};
void wxDC::DestroyClippingRegion(void)
{
m_clipping = FALSE;
};
void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const
{
if (m_clipping)
{
if (x) *x = m_clipX1;
if (y) *y = m_clipY1;
if (width) *width = (m_clipX2 - m_clipX1);
if (height) *height = (m_clipY2 - m_clipY1);
}
else
*x = *y = *width = *height = 0;
};
void wxDC::GetSize( int* width, int* height ) const
{
*width = m_maxX-m_minX;
*height = m_maxY-m_minY;
};
void wxDC::GetSizeMM( long* width, long* height ) const
{
int w = 0;
int h = 0;
GetSize( &w, &h );
*width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
*height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
};
void wxDC::SetTextForeground( const wxColour &col )
{
if (!Ok()) return;
m_textForegroundColour = col;
};
void wxDC::SetTextBackground( const wxColour &col )
{
if (!Ok()) return;
m_textBackgroundColour = col;
};
void wxDC::SetMapMode( int mode )
{
switch (mode)
{
case MM_TWIPS:
SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
break;
case MM_POINTS:
SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
break;
case MM_METRIC:
SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
break;
case MM_LOMETRIC:
SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
break;
default:
case MM_TEXT:
SetLogicalScale( 1.0, 1.0 );
break;
};
if (mode != MM_TEXT)
{
m_needComputeScaleX = TRUE;
m_needComputeScaleY = TRUE;
};
};
void wxDC::SetUserScale( double x, double y )
{
// allow negative ? -> no
m_userScaleX = x;
m_userScaleY = y;
ComputeScaleAndOrigin();
};
void wxDC::GetUserScale( double *x, double *y )
{
if (x) *x = m_userScaleX;
if (y) *y = m_userScaleY;
};
void wxDC::SetLogicalScale( double x, double y )
{
// allow negative ?
m_logicalScaleX = x;
m_logicalScaleY = y;
ComputeScaleAndOrigin();
};
void wxDC::GetLogicalScale( double *x, double *y )
{
if (x) *x = m_logicalScaleX;
if (y) *y = m_logicalScaleY;
};
void wxDC::SetLogicalOrigin( long x, long y )
{
m_logicalOriginX = x * m_signX; // is this still correct ?
m_logicalOriginY = y * m_signY;
ComputeScaleAndOrigin();
};
void wxDC::GetLogicalOrigin( long *x, long *y )
{
if (x) *x = m_logicalOriginX;
if (y) *y = m_logicalOriginY;
};
void wxDC::SetDeviceOrigin( long x, long y )
{
m_externalDeviceOriginX = x;
m_externalDeviceOriginY = y;
ComputeScaleAndOrigin();
};
void wxDC::GetDeviceOrigin( long *x, long *y )
{
if (x) *x = m_externalDeviceOriginX;
if (y) *y = m_externalDeviceOriginY;
};
void wxDC::SetInternalDeviceOrigin( long x, long y )
{
m_internalDeviceOriginX = x;
m_internalDeviceOriginY = y;
ComputeScaleAndOrigin();
};
void wxDC::GetInternalDeviceOrigin( long *x, long *y )
{
if (x) *x = m_internalDeviceOriginX;
if (y) *y = m_internalDeviceOriginY;
};
void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
{
m_signX = (xLeftRight ? 1 : -1);
m_signY = (yBottomUp ? -1 : 1);
ComputeScaleAndOrigin();
};
long wxDC::DeviceToLogicalX(long x) const
{
return XDEV2LOG(x);
};
long wxDC::DeviceToLogicalY(long y) const
{
return YDEV2LOG(y);
};
long wxDC::DeviceToLogicalXRel(long x) const
{
return XDEV2LOGREL(x);
};
long wxDC::DeviceToLogicalYRel(long y) const
{
return YDEV2LOGREL(y);
};
long wxDC::LogicalToDeviceX(long x) const
{
return XLOG2DEV(x);
};
long wxDC::LogicalToDeviceY(long y) const
{
return YLOG2DEV(y);
};
long wxDC::LogicalToDeviceXRel(long x) const
{
return XLOG2DEVREL(x);
};
long wxDC::LogicalToDeviceYRel(long y) const
{
return YLOG2DEVREL(y);
};
void wxDC::CalcBoundingBox( long x, long y )
{
if (x < m_minX) m_minX = x;
if (y < m_minY) m_minY = y;
if (x > m_maxX) m_maxX = x;
if (y > m_maxY) m_maxY = y;
};
void wxDC::ComputeScaleAndOrigin(void)
{
m_scaleX = m_logicalScaleX * m_userScaleX;
m_scaleY = m_logicalScaleY * m_userScaleY;
m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
};

773
src/gtk/dcclient.cpp Normal file
View File

@@ -0,0 +1,773 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcclient.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcclient.h"
#endif
#include "wx/dcclient.h"
//-----------------------------------------------------------------------------
// local data
//-----------------------------------------------------------------------------
#include "bdiag.xbm"
#include "fdiag.xbm"
#include "cdiag.xbm"
#include "horiz.xbm"
#include "verti.xbm"
#include "cross.xbm"
#define num_hatches 6
static GdkPixmap *hatches[num_hatches];
static GdkPixmap **hatch_bitmap = NULL;
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
#define RAD2DEG 57.2957795131
//-----------------------------------------------------------------------------
// wxPaintDC
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxPaintDC,wxDC)
wxPaintDC::wxPaintDC(void)
{
};
wxPaintDC::wxPaintDC( wxWindow *window )
{
if (!window) return;
GtkWidget *widget = window->m_wxwindow;
if (!widget) return;
m_window = widget->window;
if (!m_window) return;
if (window->m_wxwindow)
m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
else
m_cmap = gtk_widget_get_colormap( window->m_widget );
SetUpDC();
long x = 0;
long y = 0;
window->GetDrawingOffset( &x, &y );
SetInternalDeviceOrigin( -x, -y );
};
wxPaintDC::~wxPaintDC(void)
{
};
void wxPaintDC::FloodFill( long WXUNUSED(x1), long WXUNUSED(y1),
wxColour *WXUNUSED(col), int WXUNUSED(style) )
{
};
bool wxPaintDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
{
return FALSE;
};
void wxPaintDC::DrawLine( long x1, long y1, long x2, long y2 )
{
if (!Ok()) return;
if (m_pen.GetStyle() != wxTRANSPARENT)
{
gdk_draw_line( m_window, m_penGC,
XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
};
};
void wxPaintDC::CrossHair( long x, long y )
{
if (!Ok()) return;
if (m_pen.GetStyle() != wxTRANSPARENT)
{
int w = 0;
int h = 0;
GetSize( &w, &h );
long xx = XLOG2DEV(x);
long yy = YLOG2DEV(y);
gdk_draw_line( m_window, m_penGC,
0, yy, XLOG2DEVREL(w), yy );
gdk_draw_line( m_window, m_penGC,
xx, 0, xx, YLOG2DEVREL(h) );
};
};
void wxPaintDC::DrawArc( long x1, long y1, long x2, long y2, double xc, double yc )
{
if (!Ok()) return;
long xx1 = XLOG2DEV(x1);
long yy1 = YLOG2DEV(y1);
long xx2 = XLOG2DEV(x2);
long yy2 = YLOG2DEV(y2);
long xxc = XLOG2DEV((long)xc);
long yyc = YLOG2DEV((long)yc);
double dx = xx1 - xxc;
double dy = yy1 - yyc;
double radius = sqrt(dx*dx+dy*dy);
long r = (long)radius;
double radius1, radius2;
if (xx1 == xx2 && yy1 == yy2)
{
radius1 = 0.0;
radius2 = 360.0;
}
else
if (radius == 0.0)
{
radius1 = radius2 = 0.0;
}
else
{
radius1 = (xx1 - xxc == 0) ?
(yy1 - yyc < 0) ? 90.0 : -90.0 :
-atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
radius2 = (xx2 - xxc == 0) ?
(yy2 - yyc < 0) ? 90.0 : -90.0 :
-atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
};
long alpha1 = long(radius1 * 64.0);
long alpha2 = long((radius2 - radius1) * 64.0);
while (alpha2 <= 0) alpha2 += 360*64;
while (alpha1 > 360*64) alpha1 -= 360*64;
if (m_brush.GetStyle() != wxTRANSPARENT)
gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
if (m_pen.GetStyle() != wxTRANSPARENT)
gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 );
};
void wxPaintDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea )
{
if (!Ok()) return;
if (width<0) { width=-width; x=x-width; }
if (height<0) { height=-height; y=y-height; }
long xx = XLOG2DEV(x);
long yy = YLOG2DEV(y);
long ww = XLOG2DEVREL(width);
long hh = YLOG2DEVREL(height);
if (m_brush.GetStyle() != wxTRANSPARENT)
gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww-1, hh-1, 0, long(sa*64) );
if (m_pen.GetStyle() != wxTRANSPARENT)
gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, long(ea*64) );
};
void wxPaintDC::DrawPoint( long x, long y )
{
if (!Ok()) return;
if (m_pen.GetStyle() != wxTRANSPARENT)
gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) );
};
void wxPaintDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset )
{
if (!Ok()) return;
if (m_pen.GetStyle() == wxTRANSPARENT) return;
for (int i = 0; i < n-1; i++)
{
long x1 = XLOG2DEV(points[i].x + xoffset);
long x2 = XLOG2DEV(points[i+1].x + xoffset);
long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste
long y2 = YLOG2DEV(points[i+1].y + yoffset);
gdk_draw_line( m_window, m_brushGC, x1, y1, x2, y2 );
};
};
void wxPaintDC::DrawLines( wxList *points, long xoffset, long yoffset )
{
if (!Ok()) return;
if (m_pen.GetStyle() == wxTRANSPARENT) return;
wxNode *node = points->First();
while (node->Next())
{
wxPoint *point = (wxPoint*)node->Data();
wxPoint *npoint = (wxPoint*)node->Next()->Data();
long x1 = XLOG2DEV(point->x + xoffset);
long x2 = XLOG2DEV(npoint->x + xoffset);
long y1 = YLOG2DEV(point->y + yoffset); // and again...
long y2 = YLOG2DEV(npoint->y + yoffset);
gdk_draw_line( m_window, m_brushGC, x1, y1, x2, y2 );
node = node->Next();
};
};
void wxPaintDC::DrawPolygon( int WXUNUSED(n), wxPoint WXUNUSED(points)[],
long WXUNUSED(xoffset), long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
{
if (!Ok()) return;
};
void wxPaintDC::DrawPolygon( wxList *WXUNUSED(lines), long WXUNUSED(xoffset),
long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
{
if (!Ok()) return;
};
void wxPaintDC::DrawRectangle( long x, long y, long width, long height )
{
if (!Ok()) return;
long xx = XLOG2DEV(x);
long yy = YLOG2DEV(y);
long ww = XLOG2DEVREL(width);
long hh = YLOG2DEVREL(height);
if (m_brush.GetStyle() != wxTRANSPARENT)
gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh );
if (m_pen.GetStyle() != wxTRANSPARENT)
gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 );
};
void wxPaintDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius )
{
if (!Ok()) return;
if (width<0) { width=-width; x=x-width; }
if (height<0) { height=-height; y=y-height; }
if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
long xx = XLOG2DEV(x);
long yy = YLOG2DEV(y);
long ww = XLOG2DEVREL(width);
long hh = YLOG2DEVREL(height);
long rr = XLOG2DEVREL((long)radius);
long dd = 2 * rr;
if (m_brush.GetStyle() != wxTRANSPARENT)
{
gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd, hh );
gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd );
gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 );
gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
};
if (m_pen.GetStyle() != wxTRANSPARENT)
{
gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy );
gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh );
gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr );
gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr );
gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 );
gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 );
gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 );
gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 );
};
};
void wxPaintDC::DrawEllipse( long x, long y, long width, long height )
{
if (!Ok()) return;
if (width<0) { width=-width; x=x-width; }
if (height<0) { height=-height; y=y-height; }
long xx = XLOG2DEV(x);
long yy = YLOG2DEV(y);
long ww = XLOG2DEVREL(width);
long hh = YLOG2DEVREL(height);
if (m_brush.GetStyle() != wxTRANSPARENT)
gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 );
if (m_pen.GetStyle() != wxTRANSPARENT)
gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
};
bool wxPaintDC::CanDrawBitmap(void) const
{
return TRUE;
};
void wxPaintDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
{
if (!Ok()) return;
if (!icon.Ok()) return;
int xx = XLOG2DEV(x);
int yy = YLOG2DEV(y);
GdkBitmap *mask = NULL;
if (icon.GetMask()) mask = icon.GetMask()->GetBitmap();
if (useMask && mask)
{
gdk_gc_set_clip_mask( m_penGC, mask );
gdk_gc_set_clip_origin( m_penGC, xx, yy );
};
GdkPixmap *pm = icon.GetPixmap();
gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 );
if (useMask && mask)
{
gdk_gc_set_clip_mask( m_penGC, NULL );
gdk_gc_set_clip_origin( m_penGC, 0, 0 );
};
};
bool wxPaintDC::Blit( long xdest, long ydest, long width, long height,
wxDC *source, long xsrc, long ysrc, int WXUNUSED(logical_func), bool WXUNUSED(useMask) )
{
if (!Ok()) return FALSE;
wxClientDC *csrc = (wxClientDC*)source;
gdk_window_copy_area ( m_window, m_penGC,
XLOG2DEV(xdest), YLOG2DEV(ydest),
csrc->GetWindow(),
source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc),
source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height) );
/*
gdk_window_copy_area ( m_window, m_penGC,
XLOG2DEV(xdest), YLOG2DEV(ydest),
csrc->GetWindow(),
xsrc, ysrc,
width, height );
*/
return TRUE;
};
void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(use16) )
{
if (!Ok()) return;
GdkFont *font = m_font.GetInternalFont( m_scaleY );
gdk_draw_string( m_window, font, m_textGC,
XLOG2DEV(x),
YLOG2DEV(y) + font->ascent, text );
};
bool wxPaintDC::CanGetTextExtent(void) const
{
return TRUE;
};
void wxPaintDC::GetTextExtent( const wxString &string, long *width, long *height,
long *WXUNUSED(descent), long *WXUNUSED(externalLeading),
wxFont *WXUNUSED(theFont), bool WXUNUSED(use16) )
{
if (!Ok()) return;
GdkFont *font = m_font.GetInternalFont( m_scaleY );
if (width) (*width) = gdk_string_width( font, string );
if (height) (*height) = font->ascent + font->descent;
};
long wxPaintDC::GetCharWidth(void)
{
if (!Ok()) return 0;
GdkFont *font = m_font.GetInternalFont( m_scaleY );
return gdk_string_width( font, "H" );
};
long wxPaintDC::GetCharHeight(void)
{
if (!Ok()) return 0;
GdkFont *font = m_font.GetInternalFont( m_scaleY );
return font->ascent + font->descent;
};
void wxPaintDC::Clear(void)
{
if (!Ok()) return;
DestroyClippingRegion();
gdk_window_clear( m_window );
};
void wxPaintDC::SetFont( const wxFont &font )
{
if (!Ok()) return;
m_font = font;
};
void wxPaintDC::SetPen( const wxPen &pen )
{
if (!Ok()) return;
if (m_pen == pen) return;
m_pen = pen;
if (!m_pen.Ok()) return;
gint width = m_pen.GetWidth();
GdkLineStyle lineStyle = GDK_LINE_SOLID;
switch (m_pen.GetStyle())
{
case wxSOLID: { lineStyle = GDK_LINE_SOLID; break; };
case wxDOT: { lineStyle = GDK_LINE_ON_OFF_DASH; break; };
case wxLONG_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; };
case wxSHORT_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; };
case wxDOT_DASH: { lineStyle = GDK_LINE_DOUBLE_DASH; break; };
};
GdkCapStyle capStyle = GDK_CAP_ROUND;
switch (m_pen.GetCap())
{
case wxCAP_ROUND: { capStyle = GDK_CAP_ROUND; break; };
case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; };
case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; };
};
GdkJoinStyle joinStyle = GDK_JOIN_ROUND;
switch (m_pen.GetJoin())
{
case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; };
case wxJOIN_ROUND: { joinStyle = GDK_JOIN_ROUND; break; };
case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; };
};
gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );
m_pen.GetColour().CalcPixel( m_cmap );
gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
};
void wxPaintDC::SetBrush( const wxBrush &brush )
{
if (!Ok()) return;
if (m_brush == brush) return;
m_brush = brush;
if (!m_brush.Ok()) return;
m_brush.GetColour().CalcPixel( m_cmap );
gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
GdkFill fillStyle = GDK_SOLID;
switch (m_brush.GetStyle())
{
case wxSOLID:
case wxTRANSPARENT:
break;
default:
fillStyle = GDK_STIPPLED;
};
gdk_gc_set_fill( m_brushGC, fillStyle );
if (m_brush.GetStyle() == wxSTIPPLE)
{
gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
};
if (IS_HATCH(m_brush.GetStyle()))
{
int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
gdk_gc_set_stipple( m_brushGC, hatches[num] );
};
};
void wxPaintDC::SetLogicalFunction( int function )
{
if (m_logicalFunction == function) return;
GdkFunction mode = GDK_COPY;
switch (function)
{
case wxXOR: mode = GDK_INVERT; break;
case wxINVERT: mode = GDK_INVERT; break;
default: break;
};
m_logicalFunction = function;
gdk_gc_set_function( m_penGC, mode );
gdk_gc_set_function( m_brushGC, mode );
};
void wxPaintDC::SetTextForeground( const wxColour &col )
{
if (!Ok()) return;
if (m_textForegroundColour == col) return;
m_textForegroundColour = col;
if (!m_textForegroundColour.Ok()) return;
m_textForegroundColour.CalcPixel( m_cmap );
gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
};
void wxPaintDC::SetTextBackground( const wxColour &col )
{
if (!Ok()) return;
if (m_textBackgroundColour == col) return;
m_textBackgroundColour = col;
if (!m_textBackgroundColour.Ok()) return;
m_textBackgroundColour.CalcPixel( m_cmap );
gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
};
void wxPaintDC::SetBackgroundMode( int WXUNUSED(mode) )
{
};
void wxPaintDC::SetPalette( const wxPalette& WXUNUSED(palette) )
{
};
void wxPaintDC::SetClippingRegion( long x, long y, long width, long height )
{
wxDC::SetClippingRegion( x, y, width, height );
GdkRectangle rect;
rect.x = XLOG2DEV(x);
rect.y = YLOG2DEV(y);
rect.width = XLOG2DEV(x+width);
rect.height = YLOG2DEV(y+height);
gdk_gc_set_clip_rectangle( m_penGC, &rect );
gdk_gc_set_clip_rectangle( m_brushGC, &rect );
gdk_gc_set_clip_rectangle( m_textGC, &rect );
gdk_gc_set_clip_rectangle( m_bgGC, &rect );
};
void wxPaintDC::DestroyClippingRegion(void)
{
wxDC::DestroyClippingRegion();
gdk_gc_set_clip_rectangle( m_penGC, NULL );
gdk_gc_set_clip_rectangle( m_brushGC, NULL );
gdk_gc_set_clip_rectangle( m_textGC, NULL );
gdk_gc_set_clip_rectangle( m_bgGC, NULL );
};
void wxPaintDC::SetUpDC(void)
{
m_ok = TRUE;
m_logicalFunction = wxCOPY;
m_penGC = gdk_gc_new( m_window );
m_brushGC = gdk_gc_new( m_window );
m_textGC = gdk_gc_new( m_window );
m_bgGC = gdk_gc_new( m_window );
SetTextForeground( m_textForegroundColour );
SetTextBackground( m_textBackgroundColour );
SetPen( m_pen );
SetFont( m_font );
SetBrush( m_brush );
gdk_gc_set_background( m_penGC, wxWHITE->GetColor() );
if (!hatch_bitmap)
{
hatch_bitmap = hatches;
hatch_bitmap[0] = gdk_bitmap_create_from_data( NULL, bdiag_bits, bdiag_width, bdiag_height );
hatch_bitmap[1] = gdk_bitmap_create_from_data( NULL, cdiag_bits, cdiag_width, cdiag_height );
hatch_bitmap[2] = gdk_bitmap_create_from_data( NULL, fdiag_bits, fdiag_width, fdiag_height );
hatch_bitmap[3] = gdk_bitmap_create_from_data( NULL, cross_bits, cross_width, cross_height );
hatch_bitmap[4] = gdk_bitmap_create_from_data( NULL, horiz_bits, horiz_width, horiz_height );
hatch_bitmap[5] = gdk_bitmap_create_from_data( NULL, verti_bits, verti_width, verti_height );
};
};
GdkWindow *wxPaintDC::GetWindow(void)
{
return m_window;
};
// ----------------------------------- spline code ----------------------------------------
void wx_quadratic_spline(double a1, double b1, double a2, double b2,
double a3, double b3, double a4, double b4);
void wx_clear_stack(void);
int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
double *y3, double *x4, double *y4);
void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
double x4, double y4);
static bool wx_spline_add_point(double x, double y);
static void wx_spline_draw_point_array(wxDC *dc);
wxList wx_spline_point_list;
#define half(z1, z2) ((z1+z2)/2.0)
#define THRESHOLD 5
/* iterative version */
void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
double b4)
{
register double xmid, ymid;
double x1, y1, x2, y2, x3, y3, x4, y4;
wx_clear_stack();
wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
xmid = (double)half(x2, x3);
ymid = (double)half(y2, y3);
if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
wx_spline_add_point( x1, y1 );
wx_spline_add_point( xmid, ymid );
} else {
wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
(double)half(x3, x4), (double)half(y3, y4), x4, y4);
wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
(double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
}
}
}
/* utilities used by spline drawing routines */
typedef struct wx_spline_stack_struct {
double x1, y1, x2, y2, x3, y3, x4, y4;
} Stack;
#define SPLINE_STACK_DEPTH 20
static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
static Stack *wx_stack_top;
static int wx_stack_count;
void wx_clear_stack(void)
{
wx_stack_top = wx_spline_stack;
wx_stack_count = 0;
}
void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
wx_stack_top->x1 = x1;
wx_stack_top->y1 = y1;
wx_stack_top->x2 = x2;
wx_stack_top->y2 = y2;
wx_stack_top->x3 = x3;
wx_stack_top->y3 = y3;
wx_stack_top->x4 = x4;
wx_stack_top->y4 = y4;
wx_stack_top++;
wx_stack_count++;
}
int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
double *x3, double *y3, double *x4, double *y4)
{
if (wx_stack_count == 0)
return (0);
wx_stack_top--;
wx_stack_count--;
*x1 = wx_stack_top->x1;
*y1 = wx_stack_top->y1;
*x2 = wx_stack_top->x2;
*y2 = wx_stack_top->y2;
*x3 = wx_stack_top->x3;
*y3 = wx_stack_top->y3;
*x4 = wx_stack_top->x4;
*y4 = wx_stack_top->y4;
return (1);
}
static bool wx_spline_add_point(double x, double y)
{
wxPoint *point = new wxPoint ;
point->x = (int) x;
point->y = (int) y;
wx_spline_point_list.Append((wxObject*)point);
return TRUE;
}
static void wx_spline_draw_point_array(wxDC *dc)
{
dc->DrawLines(&wx_spline_point_list, 0, 0 );
wxNode *node = wx_spline_point_list.First();
while (node)
{
wxPoint *point = (wxPoint *)node->Data();
delete point;
delete node;
node = wx_spline_point_list.First();
}
}
void wxPaintDC::DrawOpenSpline( wxList *points )
{
wxPoint *p;
double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
double x1, y1, x2, y2;
wxNode *node = points->First();
p = (wxPoint *)node->Data();
x1 = p->x;
y1 = p->y;
node = node->Next();
p = (wxPoint *)node->Data();
x2 = p->x;
y2 = p->y;
cx1 = (double)((x1 + x2) / 2);
cy1 = (double)((y1 + y2) / 2);
cx2 = (double)((cx1 + x2) / 2);
cy2 = (double)((cy1 + y2) / 2);
wx_spline_add_point(x1, y1);
while ((node = node->Next()) != NULL)
{
p = (wxPoint *)node->Data();
x1 = x2;
y1 = y2;
x2 = p->x;
y2 = p->y;
cx4 = (double)(x1 + x2) / 2;
cy4 = (double)(y1 + y2) / 2;
cx3 = (double)(x1 + cx4) / 2;
cy3 = (double)(y1 + cy4) / 2;
wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
cx1 = cx4;
cy1 = cy4;
cx2 = (double)(cx1 + x2) / 2;
cy2 = (double)(cy1 + y2) / 2;
}
wx_spline_add_point( cx1, cy1 );
wx_spline_add_point( x2, y2 );
wx_spline_draw_point_array( this );
};

68
src/gtk/dcmemory.cpp Normal file
View File

@@ -0,0 +1,68 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcmemory.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcmemory.h"
#endif
#include "wx/dcmemory.h"
//-----------------------------------------------------------------------------
// wxMemoryDC
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC)
wxMemoryDC::wxMemoryDC(void)
{
m_ok = FALSE;
m_cmap = gdk_colormap_get_system();
};
wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
{
m_ok = FALSE;
m_cmap = gdk_colormap_get_system();
};
wxMemoryDC::~wxMemoryDC(void)
{
};
void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
{
m_selected = bitmap;
if (m_selected.Ok())
{
m_window = m_selected.GetPixmap();
SetUpDC();
}
else
{
m_ok = FALSE;
m_window = NULL;
};
};
void wxMemoryDC::GetSize( int *width, int *height )
{
if (m_selected.Ok())
{
if (width) (*width) = m_selected.GetWidth();
if (height) (*height) = m_selected.GetHeight();
}
else
{
if (width) (*width) = 0;
if (height) (*height) = 0;
};
};

121
src/gtk/dcscreen.cpp Normal file
View File

@@ -0,0 +1,121 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcscreen.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcscreen.h"
#endif
#include "wx/dcscreen.h"
#include "wx/window.h"
#include "gdk/gdkx.h"
//-----------------------------------------------------------------------------
// wxScreenDC
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC,wxPaintDC)
wxScreenDC::wxScreenDC(void)
{
m_ok = FALSE;
m_window = NULL;
m_cmap = gdk_colormap_get_system();
m_window = GDK_ROOT_PARENT();
SetUpDC();
gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
gdk_gc_set_subwindow( m_brushGC, GDK_INCLUDE_INFERIORS );
gdk_gc_set_subwindow( m_textGC, GDK_INCLUDE_INFERIORS );
gdk_gc_set_subwindow( m_bgGC, GDK_INCLUDE_INFERIORS );
};
wxScreenDC::~wxScreenDC(void)
{
EndDrawingOnTop();
};
bool wxScreenDC::StartDrawingOnTop( wxWindow *WXUNUSED(window) )
{
return TRUE;
/*
if (!window)
{
StartDrawingOnTop();
return;
};
wxRectangle rect;
rect.x = 0;
rect.y = 0;
window->GetPosition( &rect.x, &rect.y );
rect.width = 0;
rect.height = 0;
window->GetSize( &rect.width, &rect.height );
window->ClientToScreen( &rect.x, &rect.y );
StartDrawingOnTop( &rect );
return TRUE;
*/
};
bool wxScreenDC::StartDrawingOnTop( wxRectangle *WXUNUSED(rect) )
{
return TRUE;
/*
int x = 0;
int y = 0;
int width = gdk_screen_width();
int height = gdk_screen_height();
if (rect)
{
x = rect->x;
y = rect->y;
width = rect->width;
height = rect->height;
};
GTK cannot set transparent backgrounds. :-(
GdkWindowAttr attr;
attr.x = x;
attr.y = y;
attr.width = width;
attr.height = height;
attr.override_redirect = TRUE;
attr.wclass = GDK_INPUT_OUTPUT;
attr.event_mask = 0;
attr.window_type = GDK_WINDOW_TEMP;
m_window = gdk_window_new( NULL, &attr, GDK_WA_NOREDIR | GDK_WA_X | GDK_WA_Y );
gdk_window_show( m_window );
m_window = GDK_ROOT_PARENT();
SetUpDC();
gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
gdk_gc_set_subwindow( m_brushGC, GDK_INCLUDE_INFERIORS );
gdk_gc_set_subwindow( m_textGC, GDK_INCLUDE_INFERIORS );
gdk_gc_set_subwindow( m_bgGC, GDK_INCLUDE_INFERIORS );
return TRUE;
*/
};
bool wxScreenDC::EndDrawingOnTop(void)
{
return TRUE;
/*
if (m_window) gdk_window_destroy( m_window );
m_window = NULL;
m_isOk = FALSE;
return TRUE;
*/
};

212
src/gtk/dialog.cpp Normal file
View File

@@ -0,0 +1,212 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dialog.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dialog.h"
#endif
#include "wx/dialog.h"
#include "wx/frame.h"
#include "wx/app.h"
#include "wx/gtk/win_gtk.h"
//-----------------------------------------------------------------------------
// delete
bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
{
/*
printf( "OnDelete from " );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() );
printf( ".\n" );
*/
win->Close();
return TRUE;
};
//-----------------------------------------------------------------------------
// wxDialog
//-----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDialog,wxWindow)
EVT_BUTTON (wxID_OK, wxDialog::OnOk)
EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
EVT_CLOSE (wxDialog::OnCloseWindow)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxWindow)
wxDialog::wxDialog(void)
{
m_title = "";
m_modalShowing = TRUE;
wxTopLevelWindows.Insert( this );
};
wxDialog::wxDialog( wxWindow *parent,
wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
wxTopLevelWindows.Insert( this );
Create( parent, id, title, pos, size, style, name );
};
bool wxDialog::Create( wxWindow *parent,
wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
m_needParent = FALSE;
PreCreation( parent, id, pos, size, style, name );
m_modalShowing = ((m_windowStyle & wxDIALOG_MODAL) == wxDIALOG_MODAL);
m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL );
GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL);
gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this );
m_wxwindow = gtk_myfixed_new();
gtk_widget_show( m_wxwindow );
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
SetTitle( title );
PostCreation();
return TRUE;
};
wxDialog::~wxDialog(void)
{
wxTopLevelWindows.DeleteObject( this );
if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
};
void wxDialog::SetTitle(const wxString& title )
{
m_title = title;
gtk_window_set_title( GTK_WINDOW(m_widget), m_title );
};
wxString wxDialog::GetTitle(void) const
{
return (wxString&)m_title;
};
void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
{
if (Validate()) TransferDataFromWindow();
};
void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
{
if (IsModal())
EndModal(wxID_CANCEL);
else
{
SetReturnCode(wxID_CANCEL);
this->Show(FALSE);
};
};
void wxDialog::OnOk( wxCommandEvent &WXUNUSED(event) )
{
if ( Validate() && TransferDataFromWindow())
{
if (IsModal())
EndModal(wxID_OK);
else
{
SetReturnCode(wxID_OK);
this->Show(FALSE);
};
};
EndModal( wxID_OK );
};
void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
// yes
};
bool wxDialog::OnClose(void)
{
static wxList closing;
if (closing.Member(this)) return FALSE; // no loops
closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent);
closing.DeleteObject(this);
return FALSE;
}
void wxDialog::OnCloseWindow(wxCloseEvent& event)
{
if (GetEventHandler()->OnClose() || event.GetForce())
{
this->Destroy();
};
};
bool wxDialog::Show( const bool show )
{
if (!show && m_modalShowing)
{
EndModal( wxID_CANCEL );
};
wxWindow::Show( show );
if (show) InitDialog();
if (show && m_modalShowing)
{
gtk_grab_add( m_widget );
gtk_main();
gtk_grab_remove( m_widget );
};
return TRUE;
};
int wxDialog::ShowModal(void)
{
Show( TRUE );
return GetReturnCode();
};
void wxDialog::EndModal( int retCode )
{
gtk_main_quit();
SetReturnCode( retCode );
};
void wxDialog::InitDialog(void)
{
wxWindow::InitDialog();
};

207
src/gtk/dnd.cpp Normal file
View File

@@ -0,0 +1,207 @@
///////////////////////////////////////////////////////////////////////////////
// Name: dnd.cpp
// Purpose: wxDropTarget class
// Author: Robert Roebling
// Copyright: Robert Roebling
// Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dnd.h"
#endif
#include "wx/dnd.h"
#include "wx/window.h"
#include "wx/app.h"
#include "wx/gdicmn.h"
#include "gdk/gdkprivate.h"
#include <X11/Xlib.h>
// ----------------------------------------------------------------------------
// global
// ----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
// ----------------------------------------------------------------------------
// wxDropTarget
// ----------------------------------------------------------------------------
wxDropTarget::wxDropTarget()
{
};
wxDropTarget::~wxDropTarget()
{
};
void wxDropTarget::Drop( GdkEvent *event, int x, int y )
{
printf( "Drop data is of type %s.\n", event->dropdataavailable.data_type );
OnDrop( x, y, (char *)event->dropdataavailable.data);
};
void wxDropTarget::UnregisterWidget( GtkWidget *widget )
{
gtk_widget_dnd_drop_set( widget, FALSE, NULL, 0, FALSE );
};
// ----------------------------------------------------------------------------
// wxTextDropTarget
// ----------------------------------------------------------------------------
bool wxTextDropTarget::OnDrop( long x, long y, const void *pData )
{
OnDropText( x, y, (const char*)pData );
return TRUE;
};
bool wxTextDropTarget::OnDropText( long x, long y, const char *psz )
{
printf( "Got dropped text: %s.\n", psz );
printf( "At x: %d, y: %d.\n", (int)x, (int)y );
return TRUE;
};
void wxTextDropTarget::RegisterWidget( GtkWidget *widget )
{
char *accepted_drop_types[] = { "text/plain" };
gtk_widget_dnd_drop_set( widget, TRUE, accepted_drop_types, 1, FALSE );
};
//-------------------------------------------------------------------------
// wxDragSource
//-------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// drag request
void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDragSource *drag )
{
printf( "OnDragRequest.\n" );
gtk_widget_dnd_data_set( widget, event, drag->m_data, drag->m_size );
};
wxDragSource::wxDragSource( wxWindow *win )
{
g_blockEventsOnDrag = TRUE;
m_window = win;
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_data = NULL;
m_size = 0;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
};
wxDragSource::~wxDragSource(void)
{
g_blockEventsOnDrag = FALSE;
};
void wxDragSource::SetData( char *data, const long size )
{
m_size = size;
m_data = data;
};
void wxDragSource::Start( int x, int y )
{
if (gdk_dnd.dnd_grabbed) return;
if (gdk_dnd.drag_really) return;
if (m_size == 0) return;
if (!m_data) return;
GdkWindowPrivate *wp = (GdkWindowPrivate*) m_widget->window;
RegisterWindow();
ConnectWindow();
gdk_dnd.drag_perhaps = TRUE;
gdk_dnd.dnd_drag_start.x = 5;
gdk_dnd.dnd_drag_start.y = 5;
gdk_dnd.real_sw = wp;
if (gdk_dnd.drag_startwindows)
{
g_free( gdk_dnd.drag_startwindows );
gdk_dnd.drag_startwindows = NULL;
};
gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;
XWindowAttributes dnd_winattr;
XGetWindowAttributes( gdk_display, wp->xwindow, &dnd_winattr );
wp->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
gdk_dnd_drag_addwindow( m_widget->window );
GdkEventDragBegin ev;
ev.type = GDK_DRAG_BEGIN;
ev.window = m_widget->window;
ev.u.allflags = 0;
ev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
gdk_event_put( (GdkEvent*)&ev );
XGrabPointer( gdk_display, wp->xwindow, False,
ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, gdk_root_window, None, CurrentTime );
gdk_dnd_set_drag_cursors( m_defaultCursor.GetCursor(), m_goaheadCursor.GetCursor() );
gdk_dnd.dnd_grabbed = TRUE;
gdk_dnd.drag_really = 1;
gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE );
while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield();
UnconnectWindow();
UnregisterWindow();
};
void wxDragSource::ConnectWindow(void)
{
gtk_signal_connect( GTK_OBJECT(m_widget), "drag_request_event",
GTK_SIGNAL_FUNC(gtk_drag_callback), (gpointer)this );
};
void wxDragSource::UnconnectWindow(void)
{
if (!m_widget) return;
gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget), (gpointer)this );
};
void wxDragSource::UnregisterWindow(void)
{
if (!m_widget) return;
gtk_widget_dnd_drag_set( m_widget, FALSE, NULL, 0 );
};
//-------------------------------------------------------------------------
// wxTextDragSource
//-------------------------------------------------------------------------
void wxTextDragSource::SetTextData( const wxString &text )
{
m_tmp = text;
SetData( WXSTRINGCAST(m_tmp), m_tmp.Length()+1 );
};
void wxTextDragSource::RegisterWindow(void)
{
if (!m_widget) return;
char *accepted_drop_types[] = { "text/plain" };
gtk_widget_dnd_drag_set( m_widget, TRUE, accepted_drop_types, 1 );
};

6
src/gtk/fdiag.xbm Normal file
View File

@@ -0,0 +1,6 @@
#define fdiag_width 16
#define fdiag_height 16
static char fdiag_bits[] = {
0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20,
0x40, 0x40, 0x80, 0x80, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08,
0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80};

146
src/gtk/filedlg.cpp Normal file
View File

@@ -0,0 +1,146 @@
/////////////////////////////////////////////////////////////////////////////
// Name: filedlg.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "filedlg.h"
#endif
#include "wx/filedlg.h"
#include "wx/utils.h"
#include "wx/intl.h"
//-----------------------------------------------------------------------------
// wxFileDialog
//-----------------------------------------------------------------------------
void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), gpointer data )
{
wxFileDialog *dialog = (wxFileDialog*)data;
wxCommandEvent event(0);
dialog->OnOk( event );
};
void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(widget), gpointer data )
{
wxFileDialog *dialog = (wxFileDialog*)data;
wxCommandEvent event(0);
dialog->OnCancel( event );
};
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
const wxString& defaultDir, const wxString& defaultFileName,
const wxString& wildCard,
long style, const wxPoint& pos )
{
m_needParent = FALSE;
PreCreation( parent, -1, pos, wxDefaultSize, style, "filedialog" );
m_message = message;
m_path = "";
m_fileName = defaultFileName;
m_dir = defaultDir;
m_wildCard = wildCard;
m_filterIndex = 1;
m_widget = gtk_file_selection_new( "File selection" );
GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
};
int wxFileDialog::ShowModal(void)
{
int ret = wxDialog::ShowModal();
if (ret == wxID_OK)
{
m_fileName = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
m_path = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
};
return ret;
};
char *wxFileSelector(const char *title,
const char *defaultDir, const char *defaultFileName,
const char *defaultExtension, const char *filter, int flags,
wxWindow *parent, int x, int y)
{
wxString filter2("");
if ( defaultExtension && !filter )
filter2 = wxString("*.") + wxString(defaultExtension) ;
else if ( filter )
filter2 = filter;
wxString defaultDirString;
if (defaultDir)
defaultDirString = defaultDir;
else
defaultDirString = "";
wxString defaultFilenameString;
if (defaultFileName)
defaultFilenameString = defaultFileName;
else
defaultFilenameString = "";
wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString,
filter2, flags, wxPoint(x, y));
if ( fileDialog.ShowModal() == wxID_OK )
{
strcpy(wxBuffer, (const char *)fileDialog.GetPath());
return wxBuffer;
}
else
return NULL;
};
char* wxLoadFileSelector(const char *what, const char *extension, const char *default_name,
wxWindow *parent )
{
char *ext = (char *)extension;
char prompt[50];
wxString str = _("Load %s file");
sprintf(prompt, str, what);
if (*ext == '.') ext++;
char wild[60];
sprintf(wild, "*.%s", ext);
return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
};
char* wxSaveFileSelector(const char *what, const char *extension, const char *default_name,
wxWindow *parent )
{
char *ext = (char *)extension;
char prompt[50];
wxString str = _("Save %s file");
sprintf(prompt, str, what);
if (*ext == '.') ext++;
char wild[60];
sprintf(wild, "*.%s", ext);
return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
};

822
src/gtk/font.cpp Normal file
View File

@@ -0,0 +1,822 @@
/////////////////////////////////////////////////////////////////////////////
// Name: font.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "font.h"
#endif
#include "wx/font.h"
#include "wx/utils.h"
#include <strings.h>
//-----------------------------------------------------------------------------
// local data
//-----------------------------------------------------------------------------
static char *wx_font_family [] = {
"wxDEFAULT", "wxDECORATIVE", "wxMODERN", "wxROMAN", "wxSCRIPT",
"wxSWISS", "wxTELETYPE",
};
static char *wx_font_style [] = {
"wxDEFAULT", "wxNORMAL", "wxSLANT", "wxITALIC",
};
static char *wx_font_weight [] = {
"wxDEFAULT", "wxNORMAL", "wxBOLD", "wxLIGHT",
};
extern wxFontNameDirectory wxTheFontNameDirectory;
//-----------------------------------------------------------------------------
// wxFont
//-----------------------------------------------------------------------------
class wxFontRefData: public wxObjectRefData
{
public:
wxFontRefData(void);
~wxFontRefData(void);
wxList m_scaled_xfonts;
int m_pointSize;
int m_family, m_style, m_weight;
bool m_underlined;
int m_fontId;
char* m_faceName;
bool m_byXFontName;
GdkFont *m_font;
friend wxFont;
};
wxFontRefData::wxFontRefData(void) : m_scaled_xfonts(wxKEY_INTEGER)
{
m_byXFontName = FALSE;
m_pointSize = -1;
m_family = -1;
m_style = -1;
m_weight = -1;
m_underlined = FALSE;
m_fontId = 0;
m_faceName = NULL;
m_font = NULL;
};
wxFontRefData::~wxFontRefData(void)
{
wxNode *node = m_scaled_xfonts.First();
while (node)
{
GdkFont *font = (GdkFont*)node->Data();
wxNode *next = node->Next();
gdk_font_unref( font );
node = next;
};
if (m_faceName)
{
delete m_faceName;
m_faceName = NULL;
};
if (m_font) gdk_font_unref( m_font );
};
//-----------------------------------------------------------------------------
#define M_FONTDATA ((wxFontRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
wxFont::wxFont(void)
{
if (wxTheFontList) wxTheFontList->Append( this );
};
wxFont::wxFont( char *xFontName )
{
if (!xFontName) return;
m_refData = new wxFontRefData();
M_FONTDATA->m_byXFontName = TRUE;
M_FONTDATA->m_font = gdk_font_load( xFontName );
};
wxFont::wxFont(int PointSize, int FontIdOrFamily, int Style, int Weight,
bool Underlined, const char* Face)
{
m_refData = new wxFontRefData();
if ((M_FONTDATA->m_faceName = (Face) ? copystring(Face) : (char*)NULL) )
{
M_FONTDATA->m_fontId = wxTheFontNameDirectory.FindOrCreateFontId( Face, FontIdOrFamily );
M_FONTDATA->m_family = wxTheFontNameDirectory.GetFamily( FontIdOrFamily );
}
else
{
M_FONTDATA->m_fontId = FontIdOrFamily;
M_FONTDATA->m_family = wxTheFontNameDirectory.GetFamily( FontIdOrFamily );
};
M_FONTDATA->m_style = Style;
M_FONTDATA->m_weight = Weight;
M_FONTDATA->m_pointSize = PointSize;
M_FONTDATA->m_underlined = Underlined;
if (wxTheFontList) wxTheFontList->Append( this );
};
wxFont::wxFont(int PointSize, const char *Face, int Family, int Style,
int Weight, bool Underlined)
{
m_refData = new wxFontRefData();
M_FONTDATA->m_fontId = wxTheFontNameDirectory.FindOrCreateFontId( Face, Family );
M_FONTDATA->m_faceName = (Face) ? copystring(Face) : (char*)NULL;
M_FONTDATA->m_family = wxTheFontNameDirectory.GetFamily( M_FONTDATA->m_fontId );
M_FONTDATA->m_style = Style;
M_FONTDATA->m_weight = Weight;
M_FONTDATA->m_pointSize = PointSize;
M_FONTDATA->m_underlined = Underlined;
if (wxTheFontList) wxTheFontList->Append( this );
};
wxFont::wxFont( const wxFont& font )
{
Ref( font );
};
wxFont::wxFont( const wxFont* font )
{
UnRef();
if (font) Ref( *font );
};
wxFont::~wxFont(void)
{
if (wxTheFontList) wxTheFontList->DeleteObject( this );
};
wxFont& wxFont::operator = ( const wxFont& font )
{
if (*this == font) return (*this);
Ref( font );
return *this;
};
bool wxFont::operator == ( const wxFont& font )
{
return m_refData == font.m_refData;
};
bool wxFont::operator != ( const wxFont& font )
{
return m_refData != font.m_refData;
};
bool wxFont::Ok()
{
return (m_refData != NULL);
};
int wxFont::GetPointSize(void) const
{
return M_FONTDATA->m_pointSize;
};
wxString wxFont::GetFaceString(void) const
{
wxString s = wxTheFontNameDirectory.GetFontName( M_FONTDATA->m_fontId );
return s;
};
wxString wxFont::GetFaceName(void) const
{
wxString s = wxTheFontNameDirectory.GetFontName( M_FONTDATA->m_fontId );
return s;
};
int wxFont::GetFamily(void) const
{
return M_FONTDATA->m_family;
};
wxString wxFont::GetFamilyString(void) const
{
wxString s = wx_font_family[M_FONTDATA->m_family];
return s;
};
int wxFont::GetFontId(void) const
{
return M_FONTDATA->m_fontId; // stub
};
int wxFont::GetStyle(void) const
{
return M_FONTDATA->m_style;
};
wxString wxFont::GetStyleString(void) const
{
wxString s = wx_font_style[M_FONTDATA->m_style];
return s;
};
int wxFont::GetWeight(void) const
{
return M_FONTDATA->m_weight;
};
wxString wxFont::GetWeightString(void) const
{
wxString s = wx_font_weight[M_FONTDATA->m_weight];
return s;
};
bool wxFont::GetUnderlined(void) const
{
return M_FONTDATA->m_underlined;
};
//-----------------------------------------------------------------------------
// get internal representation of font
//-----------------------------------------------------------------------------
// local help function
static GdkFont *wxLoadQueryNearestFont(int point_size, int fontid,
int style, int weight,
bool underlined);
GdkFont *wxFont::GetInternalFont(float scale)
{
if (M_FONTDATA->m_byXFontName) return M_FONTDATA->m_font;
long int_scale = long(scale * 100.0 + 0.5); // key for fontlist
int point_scale = (M_FONTDATA->m_pointSize * 10 * int_scale) / 100;
GdkFont *font = NULL;
wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale);
if (node)
{
font = (GdkFont*)node->Data();
}
else
{
font = wxLoadQueryNearestFont( point_scale, M_FONTDATA->m_fontId, M_FONTDATA->m_style,
M_FONTDATA->m_weight, M_FONTDATA->m_underlined );
M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
};
if (!font)
printf("could not load any font");
// wxError("could not load any font", "wxFont");
return font;
};
//-----------------------------------------------------------------------------
// local utilities to find a X font
//-----------------------------------------------------------------------------
static GdkFont *wxLoadQueryFont(int point_size, int fontid, int style,
int weight, bool WXUNUSED(underlined))
{
char buffer[512];
char *name = wxTheFontNameDirectory.GetScreenName( fontid, weight, style );
if (!name)
name = "-*-*-*-*-*-*-*-%d-*-*-*-*-*-*";
sprintf(buffer, name, point_size);
return gdk_font_load( buffer );
}
static GdkFont *wxLoadQueryNearestFont(int point_size, int fontid,
int style, int weight,
bool underlined)
{
GdkFont *font;
font = wxLoadQueryFont( point_size, fontid, style, weight, underlined );
if (!font) {
// search up and down by stepsize 10
int max_size = point_size + 20 * (1 + (point_size/180));
int min_size = point_size - 20 * (1 + (point_size/180));
int i;
// Search for smaller size (approx.)
for (i=point_size-10; !font && i >= 10 && i >= min_size; i -= 10)
font = wxLoadQueryFont(i, fontid, style, weight, underlined);
// Search for larger size (approx.)
for (i=point_size+10; !font && i <= max_size; i += 10)
font = wxLoadQueryFont(i, fontid, style, weight, underlined);
// Try default family
if (!font && fontid != wxDEFAULT)
font = wxLoadQueryFont(point_size, wxDEFAULT, style,
weight, underlined);
// Bogus font
if (!font)
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
underlined);
}
return font;
}
//-----------------------------------------------------------------------------
// face names and index functions
//-----------------------------------------------------------------------------
static char *font_defaults[] = {
"FamilyDefault", "Default",
"FamilyRoman", "Roman",
"FamilyDecorative", "Decorative",
"FamilyModern", "Modern",
"FamilyTeletype", "Teletype",
"FamilySwiss", "Swiss",
"FamilyScript", "Script",
"AfmMedium", "",
"AfmBold", "Bo",
"AfmLight", "",
"AfmStraight", "",
"AfmItalic", "${AfmSlant}",
"AfmSlant", "O",
"AfmRoman", "Ro",
"AfmTimes", "Times",
"AfmHelvetica", "Helv",
"AfmCourier", "Cour",
"Afm___", "${AfmTimes,$[weight],$[style]}",
"AfmTimes__", "${AfmTimes}${Afm$[weight]}${Afm$[style]}",
"AfmTimesMediumStraight", "${AfmTimes}${AfmRoman}",
"AfmTimesLightStraight", "${AfmTimes}${AfmRoman}",
"AfmTimes_Italic", "${AfmTimes}$[weight]${AfmItalic}",
"AfmTimes_Slant", "${AfmTimes}$[weight]${AfmItalic}",
"AfmSwiss__", "${AfmHelvetica}${Afm$[weight]}${Afm$[style]}",
"AfmModern__", "${AfmCourier}${Afm$[weight]}${Afm$[style]}",
"AfmTeletype__", "${AfmModern,$[weight],$[style]}",
"PostScriptMediumStraight", "",
"PostScriptMediumItalic", "-Oblique",
"PostScriptMediumSlant", "-Oblique",
"PostScriptLightStraight", "",
"PostScriptLightItalic", "-Oblique",
"PostScriptLightSlant", "-Oblique",
"PostScriptBoldStraight", "-Bold",
"PostScriptBoldItalic", "-BoldOblique",
"PostScriptBoldSlant", "-BoldOblique",
#if WX_NORMALIZED_PS_FONTS
"PostScript___", "${PostScriptTimes,$[weight],$[style]}",
#else
"PostScriptRoman__", "${PostScriptTimes,$[weight],$[style]}",
"PostScript___", "LucidaSans${PostScript$[weight]$[style]}",
#endif
"PostScriptTimesMedium", "",
"PostScriptTimesLight", "",
"PostScriptTimesBold", "Bold",
"PostScriptTimes__", "Times${PostScript$[weight]$[style]}",
"PostScriptTimesMediumStraight", "Times-Roman",
"PostScriptTimesLightStraight", "Times-Roman",
"PostScriptTimes_Slant", "Times-${PostScriptTimes$[weight]}Italic",
"PostScriptTimes_Italic", "Times-${PostScriptTimes$[weight]}Italic",
"PostScriptSwiss__", "Helvetica${PostScript$[weight]$[style]}",
"PostScriptModern__", "Courier${PostScript$[weight]$[style]}",
"PostScriptTeletype__", "${PostScriptModern,$[weight],$[style]}",
#if !WX_NORMALIZED_PS_FONTS
"PostScriptScript__", "Zapf-Chancery-MediumItalic",
#endif
"ScreenMedium", "medium",
"ScreenBold", "bold",
"ScreenLight", "light",
"ScreenStraight", "r",
"ScreenItalic", "i",
"ScreenSlant", "o",
"ScreenDefaultBase", "misc-fixed",
"ScreenRomanBase", "*-times",
"ScreenDecorativeBase", "*-helvetica",
"ScreenModernBase", "*-courier",
"ScreenTeletypeBase", "*-lucidatypewriter",
"ScreenSwissBase", "*-lucida",
"ScreenScriptBase", "*-zapfchancery",
"ScreenStdSuffix", "-${Screen$[weight]}-${Screen$[style]}"
"-normal-*-*-%d-*-*-*-*-*-*",
"Screen___",
"-${ScreenDefaultBase}${ScreenStdSuffix}",
"ScreenRoman__",
"-${ScreenRomanBase}${ScreenStdSuffix}",
"ScreenDecorative__",
"-${ScreenDecorativeBase}${ScreenStdSuffix}",
"ScreenModern__",
"-${ScreenModernBase}${ScreenStdSuffix}",
"ScreenTeletype__",
"-${ScreenTeletypeBase}${ScreenStdSuffix}",
"ScreenSwiss__",
"-${ScreenSwissBase}${ScreenStdSuffix}",
"ScreenScript__",
"-${ScreenScriptBase}${ScreenStdSuffix}",
NULL
};
enum {wxWEIGHT_NORMAL, wxWEIGHT_BOLD, wxWEIGHT_LIGHT, wxNUM_WEIGHTS};
enum {wxSTYLE_NORMAL, wxSTYLE_ITALIC, wxSTYLE_SLANT, wxNUM_STYLES};
static int WCoordinate(int w)
{
switch (w) {
case wxBOLD: return wxWEIGHT_BOLD;
case wxLIGHT: return wxWEIGHT_LIGHT;
case wxNORMAL:
default: return wxWEIGHT_NORMAL;
}
}
static int SCoordinate(int s)
{
switch (s) {
case wxITALIC: return wxSTYLE_ITALIC;
case wxSLANT: return wxSTYLE_SLANT;
case wxNORMAL:
default: return wxSTYLE_NORMAL;
}
}
//-----------------------------------------------------------------------------
// wxSuffixMap
//-----------------------------------------------------------------------------
class wxSuffixMap {
public:
~wxSuffixMap(void);
inline char *GetName(int weight, int style)
{
return ( map [WCoordinate(weight)] [SCoordinate(style)] );
}
char *map[wxNUM_WEIGHTS][wxNUM_STYLES];
void Initialize(const char *, const char *);
};
//#if !USE_RESOURCES
#define wxGetResource(a, b, c) 0
//#endif
static void SearchResource(const char *prefix, const char **names, int count, char **v)
{
int k, i, j;
char resource[1024], **defaults, *internal;
k = 1 << count;
*v = NULL;
internal = NULL;
for (i = 0; i < k; i++) {
strcpy(resource, prefix);
for (j = 0; j < count; j++) {
if (!(i & (1 << j)))
strcat(resource, names[j]);
else
strcat(resource, "_");
}
if (wxGetResource(wxAPP_CLASS, (char *)resource, v))
return;
if (!internal) {
defaults = font_defaults;
while (*defaults) {
if (!strcmp(*defaults, resource)) {
internal = defaults[1];
break;
}
defaults += 2;
}
}
}
if (internal)
*v = copystring(internal);
}
wxSuffixMap::~wxSuffixMap(void)
{
int k, j;
for (k = 0; k < wxNUM_WEIGHTS; ++k)
for (j = 0; j < wxNUM_STYLES; ++j)
if (map[k][j]) {
delete[] map[k][j];
map[k][j] = NULL;
}
}
void wxSuffixMap::Initialize(const char *resname, const char *devresname)
{
const char *weight, *style;
char *v;
int i, j, k;
const char *names[3];
for (k = 0; k < wxNUM_WEIGHTS; k++) {
switch (k) {
case wxWEIGHT_NORMAL: weight = "Medium"; break;
case wxWEIGHT_LIGHT: weight = "Light"; break;
case wxWEIGHT_BOLD:
default: weight = "Bold";
}
for (j = 0; j < wxNUM_STYLES; j++) {
switch (j) {
case wxSTYLE_NORMAL: style = "Straight"; break;
case wxSTYLE_ITALIC: style = "Italic"; break;
case wxSTYLE_SLANT:
default: style = "Slant";
}
names[0] = resname;
names[1] = weight;
names[2] = style;
SearchResource(devresname, names, 3, &v);
/* Expand macros in the found string: */
found:
int len, closer = 0, startpos = 0;
len = (v ? strlen(v) : 0);
for (i = 0; i < len; i++) {
if (v[i] == '$' && ((v[i+1] == '[') || (v[i+1] == '{'))) {
startpos = i;
closer = (v[i+1] == '[') ? ']' : '}';
++i;
} else if (v[i] == closer) {
int newstrlen;
const char *r = NULL; bool delete_r = FALSE;
char *name;
name = v + startpos + 2;
v[i] = 0;
if (closer == '}') {
int i, count, len;
char **names;
for (i = 0, count = 1; name[i]; i++)
if (name[i] == ',')
count++;
len = i;
names = new char*[count];
names[0] = name;
for (i = 0, count = 1; i < len; i++)
if (name[i] == ',') {
names[count++] = name + i + 1;
name[i] = 0;
}
SearchResource("", (const char **)names, count, (char **)&r);
delete_r = (r != 0);
delete[] names;
if (!r) {
for (i = 0; i < len; i++)
if (!name[i])
name[i] = ',';
r = "";
printf("Bad resource name \"%s\" in font lookup\n", name);
}
} else if (!strcmp(name, "weight")) {
r = weight;
} else if (!strcmp(name, "style")) {
r = style;
} else if (!strcmp(name, "family")) {
r = resname;
} else {
r = "";
printf("Bad font macro name \"%s\"\n", name);
}
// add r to v
newstrlen = strlen(r);
char *naya = new char[startpos + newstrlen + len - i];
memcpy(naya, v, startpos);
memcpy(naya + startpos, r, newstrlen);
memcpy(naya + startpos + newstrlen, v + i + 1, len - i);
if (delete_r)
delete[] (char*)r;
delete[] v;
v = naya;
goto found;
}
}
/* We have a final value: */
map[k][j] = v;
}
}
}
//-----------------------------------------------------------------------------
// wxFontNameItem
//-----------------------------------------------------------------------------
class wxFontNameItem : public wxObject {
DECLARE_DYNAMIC_CLASS(wxFontNameItem)
public:
wxFontNameItem(const char *name, int id, int family);
~wxFontNameItem();
inline char* GetScreenName(int w, int s) {return screen.GetName(w, s);}
inline char* GetPostScriptName(int w, int s) {return printing.GetName(w, s);}
inline char* GetAFMName(int w, int s) {return afm.GetName(w, s);}
inline char* GetName(void) {return name;}
inline int GetFamily(void) {return family;}
inline int GetId(void) {return id;}
inline bool IsRoman(void) {return isroman;}
#if WXDEBUG
void Dump(ostream& str);
#endif
int id;
int family;
char *name;
wxSuffixMap screen, printing, afm;
bool isroman;
};
IMPLEMENT_ABSTRACT_CLASS(wxFontNameItem, wxObject)
wxFontNameItem::wxFontNameItem(const char *Name, int Id, int Family)
{
name = copystring(Name);
id = Id;
family = Family;
screen. Initialize(name, "Screen");
printing.Initialize(name, "PostScript");
afm. Initialize(name, "Afm");
}
wxFontNameItem::~wxFontNameItem(void)
{
if (name)
delete[] name;
name = NULL;
}
#if WXDEBUG
void wxFontNameItem::Dump(ostream& str)
{
str << "wxFontNameItem(" << name << ")";
}
#endif
//-----------------------------------------------------------------------------
// wxFontDirectory
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
wxFontNameDirectory::wxFontNameDirectory(void)
{
table = new wxHashTable(wxKEY_INTEGER, 20);
nextFontId = -1;
Initialize();
}
wxFontNameDirectory::~wxFontNameDirectory()
{
// Cleanup wxFontNameItems allocated
table->BeginFind();
wxNode *node = table->Next();
while (node) {
wxFontNameItem *item = (wxFontNameItem*)node->Data();
delete item;
node = table->Next();
}
delete table;
}
int wxFontNameDirectory::GetNewFontId(void)
{
return (nextFontId--);
}
void wxFontNameDirectory::Initialize()
{
Initialize(wxDEFAULT, wxDEFAULT, "Default");
Initialize(wxDECORATIVE, wxDECORATIVE, "Decorative");
Initialize(wxROMAN, wxROMAN, "Roman");
Initialize(wxMODERN, wxMODERN, "Modern");
Initialize(wxTELETYPE, wxTELETYPE, "Teletype");
Initialize(wxSWISS, wxSWISS, "Swiss");
Initialize(wxSCRIPT, wxSCRIPT, "Script");
}
void wxFontNameDirectory::Initialize(int fontid, int family, const char *resname)
{
char *fam, resource[256];
sprintf(resource, "Family%s", resname);
SearchResource((const char *)resource, NULL, 0, (char **)&fam);
if (fam) {
if (!strcmp(fam, "Default")) family = wxDEFAULT;
else if (!strcmp(fam, "Roman")) family = wxROMAN;
else if (!strcmp(fam, "Decorative")) family = wxDECORATIVE;
else if (!strcmp(fam, "Modern")) family = wxMODERN;
else if (!strcmp(fam, "Teletype")) family = wxTELETYPE;
else if (!strcmp(fam, "Swiss")) family = wxSWISS;
else if (!strcmp(fam, "Script")) family = wxSCRIPT;
delete[] fam; // free resource
}
table->Put(fontid, new wxFontNameItem(resname, fontid, family));
}
int wxFontNameDirectory::FindOrCreateFontId(const char *name, int family)
{
int id;
// font exists -> return id
if ( (id = GetFontId(name)) ) return id;
// create new font
Initialize(id=GetNewFontId(), family, name);
return id;
}
char *wxFontNameDirectory::GetScreenName(int fontid, int weight, int style)
{
wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
if (item)
return item->GetScreenName(weight, style);
// font does not exist
return NULL;
}
char *wxFontNameDirectory::GetPostScriptName(int fontid, int weight, int style)
{
wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
if (item)
return item->GetPostScriptName(weight, style);
// font does not exist
return NULL;
}
char *wxFontNameDirectory::GetAFMName(int fontid, int weight, int style)
{
wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
if (item)
return item->GetAFMName(weight, style);
// font does not exist
return NULL;
}
char *wxFontNameDirectory::GetFontName(int fontid)
{
wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
if (item)
return item->GetName();
// font does not exist
return NULL;
}
int wxFontNameDirectory::GetFontId(const char *name)
{
wxNode *node;
table->BeginFind();
while ( (node = table->Next()) ) {
wxFontNameItem *item = (wxFontNameItem*)node->Data();
if (!strcmp(name, item->name))
return item->id;
}
// font does not exist
return 0;
}
int wxFontNameDirectory::GetFamily(int fontid)
{
wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid);
if (item)
return item->family;
// font does not exist
return wxDEFAULT;
}

353
src/gtk/frame.cpp Normal file
View File

@@ -0,0 +1,353 @@
/////////////////////////////////////////////////////////////////////////////
// Name: frame.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "frame.h"
#endif
#include "wx/frame.h"
#include "wx/dialog.h"
#include "wx/control.h"
#include "wx/app.h"
#include "wx/gtk/win_gtk.h"
const wxMENU_HEIGHT = 28;
const wxSTATUS_HEIGHT = 25;
extern wxList wxTopLevelWindows;
extern wxList wxPendingDelete;
//-----------------------------------------------------------------------------
// wxFrame
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// size
void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win )
{
if (!win->HasVMT()) return;
/*
printf( "OnFrameResize from " );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() );
printf( ".\n" );
*/
win->GtkOnSize( alloc->width, alloc->height );
};
//-----------------------------------------------------------------------------
// delete
bool gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win )
{
/*
printf( "OnDelete from " );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() );
printf( ".\n" );
*/
win->Close();
return TRUE;
};
//-----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxFrame, wxWindow)
EVT_CLOSE(wxFrame::OnCloseWindow)
EVT_SIZE(wxFrame::OnSize)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
wxFrame::wxFrame(void)
{
m_doingOnSize = FALSE;
m_frameMenuBar = NULL;
m_frameStatusBar = NULL;
m_sizeSet = FALSE;
wxTopLevelWindows.Insert( this );
};
wxFrame::wxFrame( wxWindow *parent, const wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
m_sizeSet = FALSE;
Create( parent, id, title, pos, size, style, name );
wxTopLevelWindows.Insert( this );
};
bool wxFrame::Create( wxWindow *parent, const wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
const long style, const wxString &name )
{
m_needParent = FALSE;
m_mainWindow = NULL;
m_wxwindow = NULL;
PreCreation( parent, id, pos, size, style, name );
m_doingOnSize = FALSE;
m_title = title;
m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL );
if ((size.x != -1) && (size.y != -1))
gtk_widget_set_usize( m_widget, m_width, m_height );
if ((pos.x != -1) && (pos.y != -1))
gtk_widget_set_uposition( m_widget, m_x, m_y );
gtk_window_set_title( GTK_WINDOW(m_widget), title );
GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL);
gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this );
m_mainWindow = gtk_myfixed_new();
gtk_widget_show( m_mainWindow );
GTK_WIDGET_UNSET_FLAGS( m_mainWindow, GTK_CAN_FOCUS );
gtk_container_add( GTK_CONTAINER(m_widget), m_mainWindow );
gtk_widget_set_uposition( m_mainWindow, 0, 0 );
m_wxwindow = gtk_myfixed_new();
gtk_widget_show( m_wxwindow );
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
gtk_container_add( GTK_CONTAINER(m_mainWindow), m_wxwindow );
m_frameMenuBar = NULL;
m_frameStatusBar = NULL;
gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this );
PostCreation();
gtk_widget_realize( m_mainWindow );
return TRUE;
};
wxFrame::~wxFrame(void)
{
if (m_frameMenuBar) delete m_frameMenuBar;
if (m_frameStatusBar) delete m_frameStatusBar;
// if (m_mainWindow) gtk_widget_destroy( m_mainWindow );
wxTopLevelWindows.DeleteObject( this );
if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
};
bool wxFrame::Show( const bool show )
{
if (show)
{
wxSizeEvent event( wxSize(m_width,m_height), GetId() );
m_sizeSet = FALSE;
ProcessEvent( event );
};
return wxWindow::Show( show );
};
void wxFrame::Enable( const bool enable )
{
wxWindow::Enable( enable );
gtk_widget_set_sensitive( m_mainWindow, enable );
};
void wxFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
{
this->Destroy();
};
bool wxFrame::Destroy(void)
{
if (!wxPendingDelete.Member(this))
wxPendingDelete.Append(this);
return TRUE;
}
void wxFrame::GetClientSize( int *width, int *height ) const
{
wxWindow::GetClientSize( width, height );
if (height)
{
if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT;
if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT;
};
};
void wxFrame::GtkOnSize( int width, int height )
{
if ((m_height == height) && (m_width == width) &&
(m_sizeSet)) return;
if (!m_mainWindow) return;
if (!m_wxwindow) return;
m_width = width;
m_height = height;
gtk_widget_set_usize( m_widget, width, height );
int main_x = 0;
int main_y = 0;
int main_height = height;
int main_width = width;
// This emulates Windows behaviour:
// The menu bar is part of the main window, but the status bar
// is on the implementation side in the client area. The
// function GetClientSize returns the size of the client area
// minus the status bar height. Under wxGTK, the main window
// is represented by m_mainWindow. The menubar is inserted
// into m_mainWindow whereas the statusbar is insertes into
// m_wxwindow just like any other window.
// not really needed
gtk_widget_set_usize( m_mainWindow, width, height );
if (m_frameMenuBar)
{
main_y = wxMENU_HEIGHT;
main_height -= wxMENU_HEIGHT;
};
gtk_widget_set_uposition( GTK_WIDGET(m_wxwindow), main_x, main_y );
gtk_widget_set_usize( GTK_WIDGET(m_wxwindow), main_width, main_height );
if (m_frameMenuBar)
{
gtk_widget_set_uposition( m_frameMenuBar->m_widget, 1, 1 );
gtk_widget_set_usize( m_frameMenuBar->m_widget, width-2, wxMENU_HEIGHT-2 );
};
if (m_frameStatusBar)
{
m_frameStatusBar->SetSize( 0, main_height-wxSTATUS_HEIGHT, width, wxSTATUS_HEIGHT );
};
m_sizeSet = TRUE;
wxSizeEvent event( wxSize(m_width,m_height), GetId() );
event.SetEventObject( this );
ProcessEvent( event );
};
void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
{
wxWindow *child = NULL;
int noChildren = 0;
for(wxNode *node = GetChildren()->First(); node; node = node->Next())
{
wxWindow *win = (wxWindow *)node->Data();
if (!win->IsKindOf(CLASSINFO(wxFrame)) &&
!win->IsKindOf(CLASSINFO(wxDialog))
/* && (win != m_frameMenuBar) &&
(win != m_frameStatusBar) not in m_children anyway */
)
{
child = win;
noChildren ++;
};
}
;
if ((child) && (noChildren == 1))
{
int client_x, client_y;
GetClientSize(&client_x, &client_y);
child->SetSize( 1, 1, client_x-2, client_y);
}
;
};
void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First();
while (node)
{
wxMenuItem *menuitem = (wxMenuItem*)node->Data();
if (menuitem->m_isSubMenu) SetInvokingWindow( menuitem->m_subMenu, win );
node = node->Next();
};
};
void wxFrame::SetMenuBar( wxMenuBar *menuBar )
{
m_frameMenuBar = menuBar;
wxNode *node = m_frameMenuBar->m_menus.First();
while (node)
{
wxMenu *menu = (wxMenu*)node->Data();
SetInvokingWindow( menu, this );
node = node->Next();
};
m_frameMenuBar->m_parent = this;
gtk_myfixed_put( GTK_MYFIXED(m_mainWindow),
m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y );
};
bool wxFrame::CreateStatusBar( const int number )
{
if (m_frameStatusBar)
delete m_frameStatusBar;
m_frameStatusBar = new wxStatusBar( this, -1, wxPoint(0,0), wxSize(100,20) );
m_frameStatusBar->SetFieldsCount( number );
return TRUE;
};
void wxFrame::SetStatusText( const wxString &text, const int number )
{
if (m_frameStatusBar) m_frameStatusBar->SetStatusText( text, number );
};
void wxFrame::SetStatusWidths( const int n, const int *width )
{
if (m_frameStatusBar) m_frameStatusBar->SetStatusWidths( n, width );
};
wxStatusBar *wxFrame::GetStatusBar(void)
{
return m_frameStatusBar;
};
wxMenuBar *wxFrame::GetMenuBar(void)
{
return m_frameMenuBar;
};
void wxFrame::SetTitle( const wxString &title )
{
m_title = title;
gtk_window_set_title( GTK_WINDOW(m_widget), title );
};
wxString wxFrame::GetTitle(void) const
{
return (wxString&)m_title;
};

21
src/gtk/gdiobj.cpp Normal file
View File

@@ -0,0 +1,21 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gdiobj.cpp
// Purpose: wxGDIObject class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "gdiobj.h"
#endif
#include "wx/gdiobj.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxGDIObject, wxObject)
#endif

6
src/gtk/horiz.xbm Normal file
View File

@@ -0,0 +1,6 @@
#define horiz_width 15
#define horiz_height 15
static char horiz_bits[] = {
0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};

22
src/gtk/icon.cpp Normal file
View File

@@ -0,0 +1,22 @@
/////////////////////////////////////////////////////////////////////////////
// Name: icon.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "icon.h"
#endif
#include "wx/icon.h"
//-----------------------------------------------------------------------------
// wxIcon
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxIcon,wxBitmap)

266
src/gtk/listbox.cpp Normal file
View File

@@ -0,0 +1,266 @@
/////////////////////////////////////////////////////////////////////////////
// Name: listbox.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "listbox.h"
#endif
#include "wx/listbox.h"
//-----------------------------------------------------------------------------
// wxListBox
//-----------------------------------------------------------------------------
void gtk_listitem_select_callback( GtkWidget *widget, gpointer data )
{
wxListBox *listbox = (wxListBox*)data;
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
event.SetInt( listbox->GetIndex( widget ) );
GtkBin *bin = GTK_BIN( widget );
GtkLabel *label = GTK_LABEL( bin->child );
wxString tmp( label->label );
event.SetString( WXSTRINGCAST(tmp) );
event.SetEventObject( listbox );
listbox->ProcessEvent( event );
};
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl)
wxListBox::wxListBox(void)
{
m_list = NULL;
};
wxListBox::wxListBox( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
const int n, const wxString choices[],
const long style, const wxString &name )
{
Create( parent, id, pos, size, n, choices, style, name );
};
bool wxListBox::Create( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
const int n, const wxString choices[],
const long style, const wxString &name )
{
m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_scrolled_window_new( NULL, NULL );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
m_list = GTK_LIST( gtk_list_new() );
gtk_list_set_selection_mode( GTK_LIST(m_list), GTK_SELECTION_BROWSE );
gtk_container_add (GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) );
gtk_widget_show( GTK_WIDGET(m_list) );
for (int i = 0; i < n; i++)
{
GtkWidget *list_item;
list_item = gtk_list_item_new_with_label( choices[i] );
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
gtk_container_add( GTK_CONTAINER(m_list), list_item );
gtk_widget_show( list_item );
};
PostCreation();
Show( TRUE );
return TRUE;
};
void wxListBox::Append( const wxString &item )
{
GtkWidget *list_item;
list_item = gtk_list_item_new_with_label( item );
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
gtk_container_add( GTK_CONTAINER(m_list), list_item );
gtk_widget_show( list_item );
};
void wxListBox::Append( const wxString &WXUNUSED(item), char *WXUNUSED(clientData) )
{
};
void wxListBox::Clear(void)
{
gtk_list_clear_items( m_list, 0, Number() );
};
void wxListBox::Delete( int n )
{
gtk_list_clear_items( m_list, n, n );
};
void wxListBox::Deselect( int n )
{
gtk_list_unselect_item( m_list, n );
};
int wxListBox::FindString( const wxString &item ) const
{
GList *child = m_list->children;
int count = 0;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child );
if (item == label->label) return count;
count++;
child = child->next;
};
return -1;
};
char *wxListBox::GetClientData( const int WXUNUSED(n) ) const
{
return NULL;
};
int wxListBox::GetSelection(void) const
{
GList *selection = m_list->selection;
if (selection)
{
GList *child = m_list->children;
int count = 0;
while (child)
{
if (child->data == selection->data) return count;
count++;
child = child->next;
};
};
return -1;
};
int wxListBox::GetSelections( int **WXUNUSED(selections) ) const
{
return 0;
};
wxString wxListBox::GetString( int n ) const
{
GList *child = g_list_nth( m_list->children, n );
if (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child );
return label->label;
};
return "";
};
wxString wxListBox::GetStringSelection(void) const
{
GList *selection = m_list->selection;
if (selection)
{
GtkBin *bin = GTK_BIN( selection->data );
wxString tmp = GTK_LABEL( bin->child )->label;
return tmp;
};
return "";
};
int wxListBox::Number(void)
{
GList *child = m_list->children;
int count = 0;
while (child) { count++; child = child->next; };
return count;
};
bool wxListBox::Selected( const int n )
{
GList *target = g_list_nth( m_list->children, n );
if (target)
{
GList *child = m_list->selection;
while (child)
{
if (child->data == target->data) return TRUE;
child = child->next;
};
};
return FALSE;
};
void wxListBox::Set( const int WXUNUSED(n), const wxString *WXUNUSED(choices) )
{
};
void wxListBox::SetClientData( const int WXUNUSED(n), char *WXUNUSED(clientData) )
{
};
void wxListBox::SetFirstItem( int WXUNUSED(n) )
{
};
void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) )
{
};
void wxListBox::SetSelection( const int n, const bool select )
{
if (select)
gtk_list_select_item( m_list, n );
else
gtk_list_unselect_item( m_list, n );
};
void wxListBox::SetString( const int WXUNUSED(n), const wxString &WXUNUSED(string) )
{
};
void wxListBox::SetStringSelection( const wxString &string, const bool select )
{
SetSelection( FindString(string), select );
};
int wxListBox::GetIndex( GtkWidget *item ) const
{
if (item)
{
GList *child = m_list->children;
int count = 0;
while (child)
{
if (GTK_WIDGET(child->data) == item) return count;
count++;
child = child->next;
};
};
return -1;
};

198
src/gtk/mdi.cpp Normal file
View File

@@ -0,0 +1,198 @@
/////////////////////////////////////////////////////////////////////////////
// Name: mdi.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "mdi.h"
#endif
#include "wx/mdi.h"
//-----------------------------------------------------------------------------
// wxMDIParentFrame
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame)
wxMDIParentFrame::wxMDIParentFrame(void)
{
m_clientWindow = NULL;
m_currentChild = NULL;
m_parentFrameActive = TRUE;
};
wxMDIParentFrame::wxMDIParentFrame( wxWindow *parent,
const wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size,
const long style, const wxString& name )
{
m_clientWindow = NULL;
m_currentChild = NULL;
m_parentFrameActive = TRUE;
Create( parent, id, title, pos, size, style, name );
};
wxMDIParentFrame::~wxMDIParentFrame(void)
{
};
bool wxMDIParentFrame::Create( wxWindow *parent,
const wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size,
const long style, const wxString& name )
{
wxFrame::Create( parent, id, title, pos, size, style, name );
OnCreateClient();
return TRUE;
};
void wxMDIParentFrame::OnSize( wxSizeEvent& event )
{
wxFrame::OnSize( event );
};
void wxMDIParentFrame::OnActivate( wxActivateEvent& WXUNUSED(event) )
{
};
void wxMDIParentFrame::SetMenuBar( wxMenuBar *menu_bar )
{
wxFrame::SetMenuBar( menu_bar );
};
void wxMDIParentFrame::GetClientSize(int *width, int *height ) const
{
wxFrame::GetClientSize( width, height );
};
wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const
{
return m_currentChild;
};
wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const
{
return m_clientWindow;
};
wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void)
{
m_clientWindow = new wxMDIClientWindow( this );
return m_clientWindow;
};
void wxMDIParentFrame::ActivateNext(void)
{
};
void wxMDIParentFrame::ActivatePrevious(void)
{
};
void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(event) )
{
};
//-----------------------------------------------------------------------------
// wxMDIChildFrame
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxPanel)
wxMDIChildFrame::wxMDIChildFrame(void)
{
};
wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame *parent,
const wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size,
const long style, const wxString& name )
{
Create( parent, id, title, pos, size, style, name );
};
wxMDIChildFrame::~wxMDIChildFrame(void)
{
};
bool wxMDIChildFrame::Create( wxMDIParentFrame *parent,
const wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size,
const long style, const wxString& name )
{
m_title = title;
return wxPanel::Create( parent->GetClientWindow(), id, pos, size, style, name );
};
void wxMDIChildFrame::SetMenuBar( wxMenuBar *WXUNUSED(menu_bar) )
{
};
void wxMDIChildFrame::Activate(void)
{
};
//-----------------------------------------------------------------------------
// wxMDIClientWindow
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow)
wxMDIClientWindow::wxMDIClientWindow(void)
{
};
wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, const long style )
{
CreateClient( parent, style );
};
wxMDIClientWindow::~wxMDIClientWindow(void)
{
};
bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, const long style )
{
m_needParent = TRUE;
PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" );
m_widget = gtk_notebook_new();
PostCreation();
Show( TRUE );
return TRUE;
};
void wxMDIClientWindow::AddChild( wxWindow *child )
{
m_children.Append( child );
wxString s;
if (child->IsKindOf(CLASSINFO(wxMDIChildFrame)))
{
wxMDIChildFrame* mdi_child = (wxMDIChildFrame*) child;
s = mdi_child->m_title;
};
if (s.IsNull()) s = "MDI child";
GtkWidget *label_widget;
label_widget = gtk_label_new( s );
gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 );
gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), child->m_widget, label_widget );
};

293
src/gtk/menu.cpp Normal file
View File

@@ -0,0 +1,293 @@
/////////////////////////////////////////////////////////////////////////////
// Name: menu.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "menu.h"
#endif
#include "wx/menu.h"
//-----------------------------------------------------------------------------
// wxMenuBar
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
wxMenuBar::wxMenuBar(void)
{
m_needParent = FALSE; // hmmm
PreCreation( NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" );
m_menus.DeleteContents( TRUE );
m_widget = gtk_handle_box_new();
m_menubar = gtk_menu_bar_new();
gtk_container_add( GTK_CONTAINER(m_widget), m_menubar );
gtk_widget_show( m_menubar );
PostCreation();
Show( TRUE );
};
void wxMenuBar::Append( wxMenu *menu, const wxString &title )
{
m_menus.Append( menu );
menu->m_title = title; // ??????
size_t pos;
do {
pos = menu->m_title.First( '&' );
if (pos != wxString::npos) menu->m_title.Remove( pos, 1 );
} while (pos != wxString::npos);
GtkWidget *root_menu;
root_menu = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) );
gtk_widget_show( root_menu );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(root_menu), menu->m_menu );
gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), root_menu );
};
int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
{
if (menu->m_title == menuString)
{
int res = menu->FindItem( itemString );
if (res != -1) return res;
};
wxNode *node = menu->m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_subMenu) return FindMenuItemRecursive( item->m_subMenu, menuString, itemString );
node = node->Next();
};
return -1;
};
int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
{
wxNode *node = m_menus.First();
while (node)
{
wxMenu *menu = (wxMenu*)node->Data();
int res = FindMenuItemRecursive( menu, menuString, itemString);
if (res != -1) return res;
node = node->Next();
};
return -1;
};
//-----------------------------------------------------------------------------
// wxMenu
//-----------------------------------------------------------------------------
void gtk_menu_clicked_callback( GtkWidget *widget, gpointer data )
{
wxMenu *menu = (wxMenu*)data;
int id = menu->FindMenuIdByMenuItem(widget);
if (!menu->Enabled(id)) return;
wxCommandEvent event( wxEVENT_TYPE_MENU_COMMAND, id );
event.SetEventObject( menu );
event.SetInt(id );
wxWindow *win = menu->GetInvokingWindow();
if (win) win->ProcessEvent( event );
};
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem,wxObject)
wxMenuItem::wxMenuItem(void)
{
m_id = 0;
m_text = "";
m_isCheckMenu = FALSE;
m_checked = FALSE;
m_isSubMenu = FALSE;
m_subMenu = NULL;
m_helpStr = "";
m_menuItem = NULL;
};
IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
wxMenu::wxMenu( const wxString &title )
{
m_title = title;
m_items.DeleteContents( TRUE );
m_invokingWindow = NULL;
m_menu = gtk_menu_new(); // Do not show!
};
void wxMenu::AppendSeparator(void)
{
wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = -1;
mitem->m_text = "";
mitem->m_helpStr = "";
mitem->m_isCheckMenu = FALSE;
mitem->m_isEnabled = TRUE;
mitem->m_menuItem = gtk_menu_item_new();
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem );
};
void wxMenu::Append( const int id, const wxString &item, const wxString &helpStr, const bool checkable )
{
wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = id;
mitem->m_text = item;
size_t pos;
do {
pos = mitem->m_text.First( '&' );
if (pos != wxString::npos) mitem->m_text.Remove( pos, 1 );
} while (pos != wxString::npos);
mitem->m_helpStr = helpStr;
mitem->m_isCheckMenu = checkable;
mitem->m_isEnabled = TRUE;
if (checkable)
mitem->m_menuItem = gtk_check_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) );
else
mitem->m_menuItem = gtk_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) );
gtk_signal_connect( GTK_OBJECT(mitem->m_menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer*)this );
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem );
};
void wxMenu::Append( const int id, const wxString &item, wxMenu *subMenu, const wxString &helpStr )
{
wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = id;
mitem->m_text = item;
mitem->m_isEnabled = TRUE;
size_t pos;
do {
pos = mitem->m_text.First( '&' );
if (pos != wxString::npos) mitem->m_text.Remove( pos, 1 );
} while (pos != wxString::npos);
mitem->m_helpStr = helpStr;
mitem->m_menuItem = gtk_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) );
mitem->m_subMenu = subMenu;
gtk_menu_item_set_submenu( GTK_MENU_ITEM(mitem->m_menuItem), subMenu->m_menu );
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem );
};
int wxMenu::FindItem( const wxString itemString ) const
{
wxString s( itemString );
size_t pos;
do {
pos = s.First( '&' );
if (pos != wxString::npos) s.Remove( pos, 1 );
} while (pos != wxString::npos);
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_text == s) return item->m_id;
node = node->Next();
};
return -1;
};
void wxMenu::Enable( const int id, const bool enable )
{
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_id == id)
{
item->m_isEnabled = enable;
return;
};
node = node->Next();
};
};
bool wxMenu::Enabled( const int id ) const
{
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_id == id) return item->m_isEnabled;
node = node->Next();
};
return FALSE;
};
void wxMenu::SetLabel( const int id, const wxString &label )
{
wxString s( label );
size_t pos;
do {
pos = s.First( '&' );
if (pos != wxString::npos) s.Remove( pos, 1 );
} while (pos != wxString::npos);
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
item->m_text = s;
if (item->m_id == id)
{
gtk_label_set( GTK_LABEL( GTK_BIN(item->m_menuItem)->child ), WXSTRINGCAST(s) );
};
node = node->Next();
};
};
int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
{
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_menuItem == menuItem) return item->m_id;
node = node->Next();
};
return -1;
};
void wxMenu::SetInvokingWindow( wxWindow *win )
{
m_invokingWindow = win;
};
wxWindow *wxMenu::GetInvokingWindow(void)
{
return m_invokingWindow;
};

106
src/gtk/palette.cpp Normal file
View File

@@ -0,0 +1,106 @@
/////////////////////////////////////////////////////////////////////////////
// Name: palette.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "palette.h"
#endif
#include "wx/palette.h"
//-----------------------------------------------------------------------------
// wxPalette
//-----------------------------------------------------------------------------
class wxPaletteRefData: public wxObjectRefData
{
public:
wxPaletteRefData(void);
~wxPaletteRefData(void);
GdkColormap *m_colormap;
};
wxPaletteRefData::wxPaletteRefData(void)
{
m_colormap = NULL;
};
wxPaletteRefData::~wxPaletteRefData(void)
{
if (m_colormap) gdk_colormap_unref( m_colormap );
};
//-----------------------------------------------------------------------------
#define M_PALETTEDATA ((wxPaletteRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxPalette,wxGDIObject)
wxPalette::wxPalette(void)
{
};
wxPalette::wxPalette( const int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue )
{
m_refData = new wxPaletteRefData();
Create( n, red, green, blue );
};
wxPalette::wxPalette( const wxPalette& palette )
{
Ref( palette );
};
wxPalette::wxPalette( const wxPalette* palette )
{
UnRef();
if (palette) Ref( *palette );
};
wxPalette::~wxPalette(void)
{
};
wxPalette& wxPalette::operator = ( const wxPalette& palette )
{
if (*this == palette) return (*this);
Ref( palette );
return *this;
};
bool wxPalette::operator == ( const wxPalette& palette )
{
return m_refData == palette.m_refData;
};
bool wxPalette::operator != ( const wxPalette& palette )
{
return m_refData != palette.m_refData;
};
bool wxPalette::Ok(void) const
{
return (m_refData);
};
bool wxPalette::Create( const int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
{
};
int wxPalette::GetPixel( const unsigned char red, const unsigned char green, const unsigned char blue ) const
{
};
bool wxPalette::GetRGB( const int pixel, unsigned char *red, unsigned char *green, unsigned char *blue ) const
{
};

204
src/gtk/pen.cpp Normal file
View File

@@ -0,0 +1,204 @@
/////////////////////////////////////////////////////////////////////////////
// Name: pen.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "pen.h"
#endif
#include "wx/pen.h"
//-----------------------------------------------------------------------------
// wxPen
//-----------------------------------------------------------------------------
class wxPenRefData: public wxObjectRefData
{
public:
wxPenRefData(void);
int m_width;
int m_style;
int m_joinStyle;
int m_capStyle;
wxColour m_colour;
};
wxPenRefData::wxPenRefData(void)
{
m_width = 1;
m_style = wxSOLID;
m_joinStyle = wxJOIN_ROUND;
m_capStyle = wxCAP_ROUND;
};
//-----------------------------------------------------------------------------
#define M_PENDATA ((wxPenRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
wxPen::wxPen(void)
{
if (wxThePenList) wxThePenList->AddPen( this );
};
wxPen::wxPen( const wxColour &colour, int width, int style )
{
m_refData = new wxPenRefData();
M_PENDATA->m_width = width;
M_PENDATA->m_style = style;
M_PENDATA->m_colour = colour;
if (wxThePenList) wxThePenList->AddPen( this );
};
wxPen::wxPen( const wxString &colourName, int width, int style )
{
m_refData = new wxPenRefData();
M_PENDATA->m_width = width;
M_PENDATA->m_style = style;
M_PENDATA->m_colour = colourName;
if (wxThePenList) wxThePenList->AddPen( this );
};
wxPen::wxPen( const wxPen& pen )
{
Ref( pen );
if (wxThePenList) wxThePenList->AddPen( this );
};
wxPen::wxPen( const wxPen* pen )
{
UnRef();
if (pen) Ref( *pen );
if (wxThePenList) wxThePenList->AddPen( this );
};
wxPen::~wxPen(void)
{
if (wxThePenList) wxThePenList->RemovePen( this );
};
wxPen& wxPen::operator = ( const wxPen& pen )
{
if (*this == pen) return (*this);
Ref( pen );
return *this;
};
bool wxPen::operator == ( const wxPen& pen )
{
return m_refData == pen.m_refData;
};
bool wxPen::operator != ( const wxPen& pen )
{
return m_refData != pen.m_refData;
};
void wxPen::SetColour( const wxColour &colour )
{
if (!m_refData)
m_refData = new wxPenRefData();
M_PENDATA->m_colour = colour;
};
void wxPen::SetColour( const wxString &colourName )
{
if (!m_refData)
m_refData = new wxPenRefData();
M_PENDATA->m_colour = colourName;
};
void wxPen::SetColour( const int red, const int green, const int blue )
{
if (!m_refData)
m_refData = new wxPenRefData();
M_PENDATA->m_colour.Set( red, green, blue );
};
void wxPen::SetCap( int capStyle )
{
if (!m_refData)
m_refData = new wxPenRefData();
M_PENDATA->m_capStyle = capStyle;
};
void wxPen::SetJoin( int joinStyle )
{
if (!m_refData)
m_refData = new wxPenRefData();
M_PENDATA->m_joinStyle = joinStyle;
};
void wxPen::SetStyle( int style )
{
if (!m_refData)
m_refData = new wxPenRefData();
M_PENDATA->m_style = style;
};
void wxPen::SetWidth( int width )
{
if (!m_refData)
m_refData = new wxPenRefData();
M_PENDATA->m_width = width;
};
int wxPen::GetCap(void) const
{
return M_PENDATA->m_capStyle;
};
int wxPen::GetJoin(void) const
{
if (!m_refData)
return 0;
else
return M_PENDATA->m_joinStyle;
};
int wxPen::GetStyle(void) const
{
if (!m_refData)
return 0;
else
return M_PENDATA->m_style;
};
int wxPen::GetWidth(void) const
{
if (!m_refData)
return 0;
else
return M_PENDATA->m_width;
};
wxColour &wxPen::GetColour(void) const
{
if (!m_refData)
return wxNullColour;
else
return M_PENDATA->m_colour;
};
bool wxPen::Ok(void) const
{
return (m_refData);
};

229
src/gtk/radiobox.cpp Normal file
View File

@@ -0,0 +1,229 @@
/////////////////////////////////////////////////////////////////////////////
// Name: radiobox.cpp
// Purpose:
// Author: Robert Roebling
// Created: 01/02/97
// Id:
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "radiobox.h"
#endif
#include "wx/radiobox.h"
#include "wx/dialog.h"
#include "wx/frame.h"
#include "wx/gtk/win_gtk.h"
//-----------------------------------------------------------------------------
// wxRadioBox
//-----------------------------------------------------------------------------
void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), gpointer data )
{
wxRadioBox *rb = (wxRadioBox*)data;
wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() );
event.SetInt( rb->GetSelection() );
wxString tmp( rb->GetStringSelection() );
event.SetString( WXSTRINGCAST(tmp) );
event.SetEventObject( rb );
rb->ProcessEvent(event);
};
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
wxRadioBox::wxRadioBox(void)
{
};
wxRadioBox::wxRadioBox( wxWindow *parent, const wxWindowID id, const wxString& title,
const wxPoint &pos, const wxSize &size,
const int n, const wxString choices[],
const int majorDim, const long style,
const wxString &name )
{
Create( parent, id, title, pos, size, n, choices, majorDim, style, name );
};
bool wxRadioBox::Create( wxWindow *parent, const wxWindowID id, const wxString& title,
const wxPoint &pos, const wxSize &size,
const int n, const wxString choices[],
const int WXUNUSED(majorDim), const long style,
const wxString &name )
{
m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_frame_new( title );
int x = m_x+5;
int y = m_y+15;
int maxLen = 0;
int height = 20;
// if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0))
if (n > 0)
{
GSList *radio_button_group = NULL;
for (int i = 0; i < n; i++)
{
if (i) radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) );
m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, choices[i] ) );
if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), GTK_WIDGET(m_radio), x, y );
int tmp = 22+gdk_string_measure( GTK_WIDGET(m_radio)->style->font, choices[i] );
if (tmp > maxLen) maxLen = tmp;
int width = m_width-10;
if (size.x == -1) width = tmp;
gtk_widget_set_usize( GTK_WIDGET(m_radio), width, 20 );
y += 20;
height += 20;
};
};
wxSize newSize = size;
if (newSize.x == -1) newSize.x = maxLen+10;
if (newSize.y == -1) newSize.y = height;
SetSize( newSize.x, newSize.y );
PostCreation();
Show( TRUE );
return TRUE;
};
bool wxRadioBox::Show( const bool show )
{
wxWindow::Show( show );
GSList *item = gtk_radio_button_group( m_radio );
while (item)
{
GtkWidget *w = GTK_WIDGET( item->data );
if (show) gtk_widget_show( w ); else gtk_widget_hide( w );
item = item->next;
};
return TRUE;
};
int wxRadioBox::FindString( const wxString& WXUNUSED(s) ) const
{
return 0;
};
void wxRadioBox::SetSelection( const int WXUNUSED(n) )
{
};
int wxRadioBox::GetSelection(void) const
{
GSList *item = gtk_radio_button_group( m_radio );
int count = 0;
while (item)
{
GtkButton *button = GTK_BUTTON( item->data );
if (GTK_TOGGLE_BUTTON(button)->active) return count;
count++;
item = item->next;
};
return -1;
};
wxString wxRadioBox::GetString( const int WXUNUSED(n) ) const
{
return "";
};
wxString wxRadioBox::GetLabel(void) const
{
return wxControl::GetLabel();
};
void wxRadioBox::SetLabel( const wxString& WXUNUSED(label) )
{
};
void wxRadioBox::SetLabel( const int WXUNUSED(item), const wxString& WXUNUSED(label) )
{
};
void wxRadioBox::SetLabel( const int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap) )
{
};
wxString wxRadioBox::GetLabel( const int WXUNUSED(item) ) const
{
return "";
};
void wxRadioBox::Enable( const bool WXUNUSED(enable) )
{
};
void wxRadioBox::Enable( const int WXUNUSED(item), const bool WXUNUSED(enable) )
{
};
void wxRadioBox::Show( const int WXUNUSED(item), const bool WXUNUSED(show) )
{
};
wxString wxRadioBox::GetStringSelection(void) const
{
GSList *item = gtk_radio_button_group( m_radio );
while (item)
{
GtkButton *button = GTK_BUTTON( item->data );
if (GTK_TOGGLE_BUTTON(button)->active)
{
GtkLabel *label = GTK_LABEL( button->child );
return label->label;
};
item = item->next;
};
return "";
};
bool wxRadioBox::SetStringSelection( const wxString& WXUNUSED(s) )
{
return TRUE;
};
int wxRadioBox::Number(void) const
{
int count = 0;
GSList *item = gtk_radio_button_group( m_radio );
while (item)
{
item = item->next;
count++;
};
return count;
};
int wxRadioBox::GetNumberOfRowsOrCols(void) const
{
return 1;
};
void wxRadioBox::SetNumberOfRowsOrCols( const int WXUNUSED(n) )
{
};

Some files were not shown because too many files have changed in this diff Show More