Exemplo n.º 1
0
GArray			GSqlDatabase::FetchArray(void)
{
	GArray tab;
	this->_result = mysql_use_result(&(this->_mysql));
	MYSQL_ROW row = NULL;
	MYSQL_FIELD *field;
	unsigned int num = mysql_num_fields(this->_result);
	field = mysql_fetch_field(this->_result);
	unsigned int i = 0;
	unsigned int j = 0;
	while ((row = mysql_fetch_row(this->_result)))
	{
		unsigned long *length = mysql_fetch_lengths(this->_result);
		length = mysql_fetch_lengths(this->_result);
        i = 0;
		GStringMap map;
		while (i < num)
        {
			if (row[i])
			{
				GString sub = GString::GetBuffer(row[i], (int)length[i]);
				map[field[i].name] = sub;
			}
			++i;
        }
		++j;
		tab.PushBack(map);
	}
    mysql_free_result(this->_result);
	return (tab);
}
Exemplo n.º 2
0
int GWindow::OnDrop(char *Format, GVariant *Data, GdcPt2 Pt, int KeyState)
{
	int Status = DROPEFFECT_NONE;

	if (Format && Data)
	{
		if (stricmp(Format, LGI_FileDropFormat) == 0)
		{
			GArray<char*> Files;
			if (Data->IsBinary())
			{
				GToken Uri(	(char*)Data->Value.Binary.Data,
							"\r\n,",
							true,
							Data->Value.Binary.Length);
				for (int n=0; n<Uri.Length(); n++)
				{
					char *File = Uri[n];
					if (strnicmp(File, "file:", 5) == 0)
						File += 5;
					
					char *i = File, *o = File;
					while (*i)
					{
						if (i[0] == '%' &&
							i[1] &&
							i[2])
						{
							char h[3] = { i[1], i[2], 0 };
							*o++ = htoi(h);
							i += 3;
						}
						else
						{
							*o++ = *i++;
						}
					}
					*o++ = 0;
					
					if (FileExists(File))
					{
						Files.Add(NewStr(File));
					}
				}
			}
			
			if (Files.Length())
			{
				Status = DROPEFFECT_COPY;
				OnReceiveFiles(Files);
				Files.DeleteArrays();
			}
		}
	}
	
	return Status;
}
Exemplo n.º 3
0
bool LgiGetAppForMimeType(const char *Mime, char *AppPath, int BufSize)
{
	GArray<GAppInfo*> Apps;
	if (AppPath && LgiGetsAppForMimeType(Mime, Apps, 1))
	{
		strcpy_s(AppPath, BufSize, Apps[0]->Path);
		Apps.DeleteObjects();
		return true;
	}
	
	return false;
}
Exemplo n.º 4
0
GMessage::Result GWindow::OnEvent(GMessage *Msg)
{
	switch (MsgCode(Msg))
	{
		case B_SIMPLE_DATA:
		{
			GArray<char*> Files;
			int32 Count = 0;
			type_code Type = 0;
			
			if (Msg->GetInfo("refs", &Type, &Count) == B_OK)
			{
				for (int i=0; i<Count; i++)
				{
					entry_ref Ref;
					if (Msg->FindRef("refs", i, &Ref) == B_OK)
					{
						BPath Path("");
						BEntry Entry(&Ref, true);
						Entry.GetPath(&Path);
						char *p = (char*) Path.Path();
						if (p)
						{
							Files.Add(NewStr(p));
						}
					}
				}
			}
			
			if (Files.Length() > 0)
			{
				OnReceiveFiles(Files);
			}
			
			Files.DeleteArrays();
			break;
		}
		case M_COMMAND:
		{
			int32 Cmd = 0;
			int32 Event = 0;
			Msg->FindInt32("Cmd", &Cmd);
			Msg->FindInt32("Event", &Event);
			OnCommand(Cmd, Event, 0);
			break;
		}
	}

	return GView::OnEvent(Msg);
}
Exemplo n.º 5
0
void GDocApp<OptionsFmt>::OnReceiveFiles(GArray<char*> &Files)
{
	char *f = Files.Length() ? Files[0] : 0;
	if (f && _OpenFile(f, false))
	{
		GMru::AddFile(f);
	}
}
Exemplo n.º 6
0
void
check_for_shared_dict(GArray<GUTF8String> &argv)
{
  const int argc=argv.hbound()+1;
  for (int i=2; i<argc; i++)
    if (!argv[i].cmp("INCL=",5))
      analyze_incl_chunk(GURL::Filename::UTF8(5+(const char *)argv[i]));
    else if (!argv[i].cmp("Djbz=", 5))
      analyze_djbz_chunk(GURL::Filename::UTF8(5+(const char *)argv[i]));
}
Exemplo n.º 7
0
	int GetHookIndex(GView *Target, bool Create = false)
	{
		for (int i=0; i<Hooks.Length(); i++)
		{
			if (Hooks[i].Target == Target) return i;
		}
		
		if (Create)
		{
			HookInfo *n = &Hooks[Hooks.Length()];
			if (n)
			{
				n->Target = Target;
				n->Flags = 0;
				return Hooks.Length() - 1;
			}
		}
		
		return -1;
	}
Exemplo n.º 8
0
int GDragDropTarget::OnDrop(GArray<GDragData> &DropData,
							GdcPt2 Pt,
							int KeyState)
{
	if (DropData.Length() == 0 ||
		DropData[0].Data.Length() == 0)
		return DROPEFFECT_NONE;
	
	char *Fmt = DropData[0].Format;
	GVariant *Var = &DropData[0].Data[0];
	return OnDrop(Fmt, Var, Pt, KeyState);
}
Exemplo n.º 9
0
	GArray<GString> GString::Split(GString& str, char const token)
	{
		str.Trim(token);
		GArray<GString> arr;

		size_t lastPos = 0;
		size_t tokenPos = str.Find(token);

		while (tokenPos != -1)
		{
			arr.Add(str.SubString(lastPos, tokenPos - 1));

			lastPos = tokenPos + 1;

			tokenPos = str.Find(token, tokenPos + 1);
		}

		arr.Add(str.SubString(lastPos, str.Size() - 1));

		return arr;
	}	
Exemplo n.º 10
0
bool GDragDropSource::GetData(GArray<GDragData> &DragData)
{
	if (DragData.Length() == 0)
		return false;

	// Call the deprecated version of 'GetData'
	GVariant *v = &DragData[0].Data[0];
	char *fmt = DragData[0].Format;
	if (!v || !fmt)
		return false;

	return GetData(v, fmt);
}
Exemplo n.º 11
0
	void pileup(GArray& range, const bam1_t* read, int start, int end){
		//check if the read really overlaps
		if (start < range.end() && end >= range.loc){
		    	//Rcout << "-> took read " << std::endl;
			if (range.strand >= 0){
				//range on the reference strand
				int pos = start-range.loc;
				++range.array[pos>0?pos:0];
				pos = end + 1 - range.loc;
				if (pos < range.len){
					--range.array[pos];
				}
			} else {
				//range on the negative strand
				int pos = range.end() - 1 - end;
				++range.array[pos>0?pos:0];
				pos = range.end() - start;
				if (pos < range.len){
					--range.array[pos];
				}
			}
		}
	}
Exemplo n.º 12
0
void MultipleInstanceManager::SendParameters(const std::list<tstring>& args)
{
	GArray<TCHAR> parmarray;
	int size = 0;
	int paSize = 0;
	
	for(std::list<tstring>::const_iterator i = args.begin(); i != args.end(); ++i)
	{
		paSize = (*i).size();
		
		parmarray.grow( size + paSize + 1);

		_tcscpy(&parmarray[size], (*i).c_str());

		size += (paSize + 1);
	}

	// Append another NULL.
	parmarray.grow(size + 1);
	parmarray[size] = _T('\0');

	HANDLE	hMappedFile;
	BYTE*	buffer;

	if(RequestPermission())
	{
		if( !CreateSharedData(&buffer, &hMappedFile, parmarray.size() * sizeof(TCHAR)) )
			return;

		// Copy the big buffer into the other big buffer :)
		memcpy(buffer, &parmarray[0], parmarray.size() * sizeof(TCHAR));

		DWORD dwRecipients = BSM_APPLICATIONS;
		long res = m_pfnBSM(
			BSF_ALLOWSFW | BSF_FORCEIFHUNG | BSF_IGNORECURRENTTASK,
			&dwRecipients, 
			m_uiMessage,
			MIM_PARAMETER_ARRAY,
			parmarray.size() * sizeof(TCHAR));

		PNASSERT(res != -1);

		ReleaseSharedData(buffer, hMappedFile);
		Release();
	}
	else
	{
		LOG(_T("PN failed to enter mutex to send parameters"));
	}
}
Exemplo n.º 13
0
void
create_info_chunk(IFFByteStream &iff, GArray<GUTF8String> &argv)
{
  const int argc=argv.hbound()+1;
  // Process info specification
  for (int i=2; i<argc; i++)
    if (!argv[i].cmp("INFO=",5))
      {
        int   narg = 0;
        const char *ptr = 5+(const char *)argv[i];
        while (*ptr)
          {
            if (*ptr != ',')
              {
                int x = strtol((char *)ptr, (char **)&ptr, 10);
                switch(narg)
                  {
                  case 0: 
                    w = x; break;
                  case 1: 
                    h = x; break;
                  case 2: 
                    dpi = x; break;
                  default:  
                    G_THROW("djvumake: incorrect 'INFO' chunk specification\n");
                  }
              }
            narg++;
            if (*ptr && *ptr++!=',')
              G_THROW("djvumake: comma expected in 'INFO' chunk specification\n");
          }
          break;
      }
  if (w>0 && (w<=0 || w>=32768))
    G_THROW("djvumake: incorrect width in 'INFO' chunk specification\n");
  if (h>0 && (h<=0 || h>=32768))
    G_THROW("djvumake: incorrect height in 'INFO' chunk specification\n");
  if (dpi>0 && (dpi<25 || dpi>6000))
    G_THROW("djvumake: incorrect dpi in 'INFO' chunk specification\n");
  // Search first mask chunks if size is still unknown
  if (h<0 || w<0)
    {
      for (int i=2; i<argc; i++)
        if (!argv[i].cmp("Sjbz=",5))
          {
            analyze_jb2_chunk(GURL::Filename::UTF8(5+(const char *)argv[i]));
            break;
          }
        else if (!argv[i].cmp("Smmr=",5))
          {
            analyze_mmr_chunk(GURL::Filename::UTF8(5+(const char *)argv[i]));
            break;
          }
    }
  
  // Check that we have everything
  if (w<0 || h<0)
    G_THROW("djvumake: cannot determine image size\n");
  // write info chunk
  GP<DjVuInfo> ginfo=DjVuInfo::create();
  DjVuInfo &info=*ginfo;
  info.width = w;
  info.height = h;
  info.dpi = dpi;
  iff.put_chunk("INFO");
  info.encode(*iff.get_bytestream());
  iff.close_chunk();
}
Exemplo n.º 14
0
GMessage::Result GWindow::OnEvent(GMessage *Msg)
{
	int Status = 0;

	switch (MsgCode(Msg))
	{
		case M_SET_WINDOW_PLACEMENT:
		{
			/*	
				Apparently if you use SetWindowPlacement inside the WM_CREATE handler,
				then the restored rect doesn't "stick", it gets stomped on by windows.
				So this code... RESETS it to be what we set earlier. Windows sucks.
			*/
			if (d->Wp)
			{
				if (_View)
				{
					GRect r = d->Wp->rcNormalPosition;

					if (!GView::Visible())
					{
						d->Wp->showCmd = SW_HIDE;
					}

					#if DEBUG_WINDOW_PLACEMENT
					LgiTrace("%s:%i - SetWindowPlacement, pos=%s, show=%i\n", __FILE__, __LINE__, r.GetStr(), d->Wp->showCmd);
					#endif

					SetWindowPlacement(_View, d->Wp);
				}
				DeleteObj(d->Wp);
			}
			break;
		}
		case WM_SYSCOLORCHANGE:
		{
			LgiInitColours();
			break;
		}
		case WM_WINDOWPOSCHANGING:
		{
			bool Icon = IsIconic(Handle());
			bool Zoom = IsZoomed(Handle());

			if (!Icon && (_Dialog || !Zoom))
			{
				WINDOWPOS *Info = (LPWINDOWPOS) Msg->b;
				if (!Info)
				    break;
				    
				if (Info->flags == (SWP_NOSIZE | SWP_NOMOVE) && _Dialog)
				{
				    // Info->flags |= SWP_NOZORDER;
				    Info->hwndInsertAfter = _Dialog->Handle();
				}

				if (GetMinimumSize().x &&
					GetMinimumSize().x > Info->cx)
				{
					Info->cx = GetMinimumSize().x;
				}

				if (GetMinimumSize().y &&
					GetMinimumSize().y > Info->cy)
				{
					Info->cy = GetMinimumSize().y;
				}

				RECT Rc;
				if (d->SnapToEdge &&
					SystemParametersInfo(SPI_GETWORKAREA, 0, &Rc, SPIF_SENDCHANGE))
				{
					GRect r = Rc;
					GRect p(Info->x,
					        Info->y,
					        Info->x + Info->cx - 1,
					        Info->y + Info->cy - 1);
					
					if (r.Valid() && p.Valid())
					{
						int Snap = 12;

						if (abs(p.x1 - r.x1) <= Snap)
						{
							// Snap left edge
							Info->x = r.x1;
						}
						else if (abs(p.x2 - r.x2) <= Snap)
						{
							// Snap right edge
							Info->x = r.x2 - Info->cx + 1;
						}

						if (abs(p.y1 - r.y1) <= Snap)
						{
							// Snap top edge
							Info->y = r.y1;
						}
						else if (abs(p.y2 - r.y2) <= Snap)
						{
							// Snap bottom edge
							Info->y = r.y2 - Info->cy + 1;
						}
					}
				}
			}
			break;
		}
		case WM_SIZE:
		{
			if (Visible())
			{
				GWindowZoom z = d->Show;
				switch (Msg->a)
				{
					case SIZE_MINIMIZED:
					{
						z = GZoomMin;
						break;
					}
					case SIZE_MAXIMIZED:
					{
						z = GZoomMax;
						break;
					}
					case SIZE_RESTORED:
					{
						z = GZoomNormal;
						break;
					}
				}
				if (z != d->Show)
				{
					OnZoom(d->Show = z);
				}
			}

			Status = GView::OnEvent(Msg);
			break;
		}
		case WM_ACTIVATE:
		{
			// This is a hack to make Windows set the focus of a child
			// control when you Alt-Tab in and out of a top level window
			if (LOWORD(Msg->a) != WA_INACTIVE)
			{
				/*
				// gaining focus
				if (LastFocus)
				{
					if (In_SetWindowPos)
					{
						assert(0);
						LgiTrace("%s:%i - %s->SetFocus()\n", __FILE__, __LINE__, GetClass());
					}
					SetFocus(LastFocus);
					LastFocus = 0;
				}
				
				if (d->Focus && d->Focus->Handle())
				{
					if (In_SetWindowPos)
					{
						assert(0);
						LgiTrace("%s:%i - %s->SetFocus()\n", __FILE__, __LINE__, GetClass());
					}
					else
					{					
						::SetFocus(d->Focus->Handle());
					}
				}
				*/
			}
			/*
			else
			{
				// losing focus
				LastFocus = 0;
				HWND f = GetFocus();
				for (HWND p = ::GetParent(f); p; p = ::GetParent(p))
				{
					if (p == Handle())
					{
						LastFocus = f;
					}
				}
			}
			*/
			break;
		}
		case WM_CREATE:
		{
			Pour();
			OnCreate();

			if (!_Default)
			{
				_Default = FindControl(IDOK);
				if (_Default)
				{
					_Default->Invalidate();
				}
			}

			d->InCreate = false;
			if (d->Wp)
			{
				PostEvent(M_SET_WINDOW_PLACEMENT);
			}
			break;
		}
		case WM_WINDOWPOSCHANGED:
		{
			DeleteObj(d->Wp);
			Status = GView::OnEvent(Msg);
			break;
		}
		case WM_QUERYENDSESSION:
	 	case WM_CLOSE:
		{
			bool QuitApp;
			if (QuitApp = OnRequestClose(MsgCode(Msg) == WM_QUERYENDSESSION))
			{
				Quit();
			}

			if (MsgCode(Msg) == WM_CLOSE)
			{
				return 0;
			}
			else
			{
				return QuitApp;
			}
			break;
		}
		case WM_SYSCOMMAND:
		{
		    if (Msg->a == SC_CLOSE)
		    {
    			if (OnRequestClose(false))
    		    {
    		        Quit();
    		    }

   		        return 0;
		    }
		    else
		    {
			    Status = GView::OnEvent(Msg);
			}
		    break;
		}
		case WM_DROPFILES:
		{
			HDROP hDrop = (HDROP) Msg->a;
			if (hDrop)
			{
				GArray<char*> FileNames;
				int Count = 0;
				
				Count = DragQueryFileW(hDrop, -1, NULL, 0);

				for (int i=0; i<Count; i++)
				{
					char16 FileName[256];
					if (DragQueryFileW(hDrop, i, FileName, sizeof(FileName)-1) > 0)
					{
						FileNames.Add(LgiNewUtf16To8(FileName));
					}
				}

				OnReceiveFiles(FileNames);
				FileNames.DeleteArrays();
			}
			break;
		}
		case M_HANDLEMOUSEMOVE:
		{
			// This receives events fired from the GMouseHookPrivate class so that
			// non-LGI windows create mouse hook events as well.
			GTempView v((OsView)MsgB(Msg));
			GMouse m;
			m.x = LOWORD(MsgA(Msg));
			m.y = HIWORD(MsgA(Msg));
			HandleViewMouse(&v, m);
			break;
		}
		case M_COMMAND:
		{
			HWND OurWnd = Handle(); // copy onto the stack, because
									// we might lose the 'this' object in the
									// OnCommand handler which would delete
									// the memory containing the handle.

			Status = OnCommand(Msg->a, 0, (HWND) Msg->b);
			if (!IsWindow(OurWnd))
			{
				// The window was deleted so break out now
				break;
			}
			// otherwise fall thru to the GView handler
		}
		default:
		{
			Status = GView::OnEvent(Msg);
			break;
		}
	}

	return Status;
}